make FS visible

This commit is contained in:
Val Erastov 2022-08-09 19:36:42 -07:00
parent 1ce3c7c8ac
commit 6adcfbb569
2 changed files with 11 additions and 11 deletions

2
externals.d.ts vendored
View file

@ -4,3 +4,5 @@ declare module '*.less' {
} }
declare var verb: any; declare var verb: any;
declare var FS: any;

View file

@ -18,7 +18,6 @@ export const ImportModelOpperation: OperationDescriptor<ImportModelParams> = {
info: 'Imports BREP, STEP, IGES or FCStd file', info: 'Imports BREP, STEP, IGES or FCStd file',
paramsInfo: ({ }) => `()`, paramsInfo: ({ }) => `()`,
run: async (params: ImportModelParams, ctx: ApplicationContext) => { run: async (params: ImportModelParams, ctx: ApplicationContext) => {
//console.log(params);
let occ = ctx.occService; let occ = ctx.occService;
const oci = occ.commandInterface; const oci = occ.commandInterface;
@ -27,8 +26,6 @@ export const ImportModelOpperation: OperationDescriptor<ImportModelParams> = {
const FileName = params.file.fileName.toUpperCase(); const FileName = params.file.fileName.toUpperCase();
let rawContent = params.file.rawContent(); let rawContent = params.file.rawContent();
//console.log(params.file.content);
//console.log(rawContent);
if (FileName.endsWith("BRP") || FileName.endsWith("BREP")) { if (FileName.endsWith("BRP") || FileName.endsWith("BREP")) {
//FreeCAD some times omits this text from the top of BRP files //FreeCAD some times omits this text from the top of BRP files
@ -50,22 +47,23 @@ export const ImportModelOpperation: OperationDescriptor<ImportModelParams> = {
for (const itemToLookAt in DecodedXmlFreeCADData) { for (const itemToLookAt in DecodedXmlFreeCADData) {
const flattenedObject = flattenJSON(DecodedXmlFreeCADData[itemToLookAt]); const flattenedObject = flattenJSON(DecodedXmlFreeCADData[itemToLookAt]);
let importBrepFlag = false;
let importBrepShapeName = ""; let importBrepShapeName = "";
let visiblePropertyName = ""; let visiblePropertyName = "";
for (const propertyToLookAt in flattenedObject) { for (const propertyToLookAt in flattenedObject) {
if (propertyToLookAt.includes("Part.0.$.file")) importBrepShapeName = flattenedObject[propertyToLookAt]; if (propertyToLookAt.includes("Part.0.$.file")) importBrepShapeName = flattenedObject[propertyToLookAt];
if (importBrepShapeName !== "PartShape.brp"){ if (importBrepShapeName !== "PartShape.brp"){
if (propertyToLookAt.includes("$.name") && flattenedObject[propertyToLookAt] == "Visibility") { if (propertyToLookAt.includes("$.name") && flattenedObject[propertyToLookAt] == "Visibility") {
let propToCheck = await propertyToLookAt.replace(".$.name", ".Bool.0.$.value"); let propToCheck = propertyToLookAt.replace(".$.name", ".Bool.0.$.value");
let shouldItImport = await flattenedObject[propToCheck]; let shouldItImport = flattenedObject[propToCheck];
console.log(shouldItImport, importBrepShapeName);
//alert(shouldItImport);
if (shouldItImport == "true") { if (shouldItImport == "true") {
try { try {
await FS.writeFile(importBrepShapeName, `DBRep_DrawableShape\n` + await zipContents[importBrepShapeName].async("string")); const zipBrepContent = zipContents[importBrepShapeName];
await oci.readbrep(importBrepShapeName, importBrepShapeName); if (!zipBrepContent) {
continue;
}
const zipContent = await zipBrepContent.async("string");
FS.writeFile(importBrepShapeName, `DBRep_DrawableShape\n` + zipContent);
oci.readbrep(importBrepShapeName, importBrepShapeName);
returnObject.created.push(occ.io.getShell(importBrepShapeName)); returnObject.created.push(occ.io.getShell(importBrepShapeName));
console.log(importBrepShapeName); console.log(importBrepShapeName);
} catch (e) { } catch (e) {