From: Jérôme Date: Mon, 12 Oct 2020 09:32:20 +0000 (+0200) Subject: Fix issues for first level and tests X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d656b20c93f9651bf7f0f135ebecd35fa9ee59b9;p=modules%2Fshaper.git Fix issues for first level and tests --- diff --git a/src/ExchangeAPI/ExchangeAPI_Import.cpp b/src/ExchangeAPI/ExchangeAPI_Import.cpp index d5d7ea2a9..059467a25 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Import.cpp @@ -67,16 +67,19 @@ ExchangeAPI_Import::~ExchangeAPI_Import() } //-------------------------------------------------------------------------------------- -void ExchangeAPI_Import::setParameters(const std::string & theFilePath, +void ExchangeAPI_Import::setParameters(const std::string & theFilePath, const bool anScalInterUnits, const bool anMaterials, const bool anColor) { fillAttribute(theFilePath, mystepfilePath); fillAttribute("STEP", feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID())); - fillAttribute(anScalInterUnits, feature()->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())); - fillAttribute(anMaterials, feature()->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())); - fillAttribute(anColor, feature()->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())); + fillAttribute(anScalInterUnits, + feature()->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())); + fillAttribute(anMaterials, + feature()->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())); + fillAttribute(anColor, + feature()->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())); execute(); } @@ -84,7 +87,16 @@ void ExchangeAPI_Import::setParameters(const std::string & theFilePath, void ExchangeAPI_Import::setFilePath(const std::string & theFilePath) { fillAttribute(theFilePath, myfilePath); - std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFilePath); + std::string aFrom = "\\"; + std::string aTo = "\\\\"; + std::string aFilePath = theFilePath; + for(std::size_t aPos = aFilePath.find(aFrom); + aPos != std::string::npos; + aPos = aFilePath.find(aFrom, aPos)) { + aFilePath.replace(aPos, aFrom.size(), aTo); + aPos += aTo.size(); + } + std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath); fillAttribute(anExtension, feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID())); execute(); } @@ -95,7 +107,8 @@ void ExchangeAPI_Import::dump(ModelHighAPI_Dumper& theDumper) const FeaturePtr aBase = feature(); std::string aPartName = theDumper.name(aBase->document()); - AttributeStringPtr aImportTypeAttr = aBase->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()); + AttributeStringPtr aImportTypeAttr = + aBase->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()); std::string aFormat = aImportTypeAttr->value(); std::string aFilePath; if (aFormat == "STEP" || aFormat == "STP") @@ -118,7 +131,7 @@ void ExchangeAPI_Import::dump(ModelHighAPI_Dumper& theDumper) const theDumper << aBase << " = model.addImportStep(" << aPartName << ", \"" << aFilePath << "\"" ; - theDumper << ", " << scalinterunits()->value() + theDumper << ", " << scalinterunits()->value() << ", " << materials()->value() << ", " << colors()->value() << ")"<< std::endl; }else{ diff --git a/src/ExchangeAPI/ExchangeAPI_Import.h b/src/ExchangeAPI/ExchangeAPI_Import.h index d95a45389..90562443a 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.h +++ b/src/ExchangeAPI/ExchangeAPI_Import.h @@ -51,10 +51,10 @@ public: EXCHANGEAPI_EXPORT ExchangeAPI_Import(const std::shared_ptr & theFeature, const std::string & theFilePath, - const bool anScalInterUnits, - const bool anMaterials, - const bool anColor); - + const bool theScalInterUnits, + const bool theMaterials, + const bool theColor); + /// Destructor EXCHANGEAPI_EXPORT virtual ~ExchangeAPI_Import(); @@ -77,9 +77,9 @@ public: /// Set point values EXCHANGEAPI_EXPORT void setFilePath(const std::string & theFilePath); - + EXCHANGEAPI_EXPORT - void setParameters(const std::string & theFilePath, + void setParameters(const std::string & theFilePath, const bool anScalInterUnits, const bool anMaterials, const bool anColor); @@ -108,7 +108,7 @@ ImportPtr addImportStep(const std::shared_ptr & thePart, const bool anScalInterUnits, const bool anMaterials, const bool anColor); - + /** \ingroup CPPHighAPI * \brief Import features from the file to the document after the current feature (or to the end). */ diff --git a/src/ExchangePlugin/ExchangePlugin_Import.cpp b/src/ExchangePlugin/ExchangePlugin_Import.cpp index 304d456d5..22cbb89f8 100644 --- a/src/ExchangePlugin/ExchangePlugin_Import.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Import.cpp @@ -109,7 +109,7 @@ void ExchangePlugin_Import::execute() if (aFormat == "STEP" || aFormat == "STP") { aFilePathAttr = string(ExchangePlugin_Import::STEP_FILE_PATH_ID()); - aFilePath = aFilePathAttr->value(); + aFilePath = aFilePathAttr->value(); // get the document where to import aPartsAttr = stringArray(STEP_TARGET_PARTS_LIST_ID()); aTargetAttr = integer(STEP_TARGET_PART_ID()); @@ -140,8 +140,9 @@ void ExchangePlugin_Import::execute() { aPathAttr = aData->string(ExchangePlugin_ImportFeature::FILE_PATH_ID()); } - - AttributeStringPtr aImportTypeAttr = aData->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()); + + AttributeStringPtr aImportTypeAttr = + aData->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()); aData->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID()) ->setValue(boolean(ExchangePlugin_Import::STEP_MATERIALS_ID())->value()); @@ -180,10 +181,11 @@ void ExchangePlugin_Import::attributeChanged(const std::string& theID) aPartsAttr = stringArray(STEP_TARGET_PARTS_LIST_ID()); aTargetAttr = integer(STEP_TARGET_PART_ID()); updatePart(aPartsAttr, aTargetAttr); - } + } } -void ExchangePlugin_Import::updatePart(AttributeStringArrayPtr &aPartsAttr, AttributeIntegerPtr &aTargetAttr) +void ExchangePlugin_Import::updatePart(AttributeStringArrayPtr &aPartsAttr, + AttributeIntegerPtr &aTargetAttr) { // update the list of target parts SessionPtr aSession = ModelAPI_Session::get(); diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 402b660e9..2049662d1 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -93,9 +93,20 @@ void ExchangePlugin_ImportFeature::initAttributes() data()->addAttribute(STEP_SCALE_INTER_UNITS_ID(), ModelAPI_AttributeBoolean::typeId()); aFeaturesAttribute->setIsArgument(false); - + ModelAPI_Session::get()->validators()->registerNotObligatory( getKind(), ExchangePlugin_ImportFeature::FEATURES_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), ExchangePlugin_ImportFeature::STEP_COLORS_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), ExchangePlugin_ImportFeature::STEP_MATERIALS_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID()); + } /* @@ -152,13 +163,14 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) ResultBodyPtr result = document()->createBody(data()); bool anColorGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())->value(); - bool anMaterialsGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())->value(); + bool anMaterialsGroupSelected = + boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())->value(); if (anExtension == "BREP" || anExtension == "BRP") { aGeomShape = BREPImport(theFileName, anExtension, anError); } else if (anExtension == "STEP" || anExtension == "STP") { - bool anScalInterUnits = boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value(); - + bool anScalInterUnits = + boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value(); try{ @@ -175,10 +187,11 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) if (aFeature) document()->removeFeature(aFeature); } - + aGeomShape = STEPImportAttributs(theFileName, result, anScalInterUnits, - anMaterialsGroupSelected, anColorGroupSelected,theMaterialShape,anError); - + anMaterialsGroupSelected, anColorGroupSelected, + theMaterialShape,anError); + } catch (OSD_Exception& e) { //Try to load STEP file without colors... @@ -201,7 +214,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) loadNamingDS(aGeomShape, result); // create color group - if (anColorGroupSelected) + if (anColorGroupSelected) { setColorGroups(result); } @@ -211,15 +224,16 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) setMaterielGroup(result,theMaterialShape); } - setResult(result); + setResult(result); } -void ExchangePlugin_ImportFeature::setColorGroups(std::shared_ptr theResultBody) +void ExchangePlugin_ImportFeature::setColorGroups( + std::shared_ptr theResultBody) { std::vector aColor; - int indice = 1; - std::list< std::vector > aColorsRead; + int indice = 1; + std::list< std::vector > aColorsRead; ModelAPI_Tools::getColor(theResultBody, aColor); @@ -240,7 +254,7 @@ void ExchangePlugin_ImportFeature::setColorGroups(std::shared_ptrshape(); aSelectionList->setSelectionType(aShape->shapeTypeStr() ); aSelectionList->append(theResultBody,aShape); - } + } } - // add element with the same color + // add element with the same color std::list allRes; ModelAPI_Tools::allSubs(theResultBody, allRes); - for(std::list::iterator aRes = allRes.begin(); + for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) { ModelAPI_Tools::getColor(*aRes, aColor); GeomShapePtr aShape = (*aRes)->shape(); @@ -285,38 +299,41 @@ void ExchangePlugin_ImportFeature::setColorGroup(std::shared_ptrlastResult(),theColor); + if (aSelectionList->size() == 0 ){ document()->removeFeature(aGroupFeature); } } -void ExchangePlugin_ImportFeature::setMaterielGroup(std::shared_ptr theResultBody, - std::map< std::wstring, std::list> &theMaterialShape) +void ExchangePlugin_ImportFeature::setMaterielGroup( + std::shared_ptr theResultBody, + std::map< std::wstring, + std::list> &theMaterialShape) { - int indice = 1; - std::map< std::wstring, std::list>::iterator it; + int indice = 1; + std::map< std::wstring, std::list>::iterator it; for( it = theMaterialShape.begin(); it != theMaterialShape.end(); ++it) { - + std::shared_ptr aGroupFeature = addFeature("Group"); // group name aGroupFeature->data()->setName((*it).first); // fill selection AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list"); - std::string aSelectionType = "solid" ; - aSelectionList->setSelectionType(aSelectionType); GeomShapePtr aShape = theResultBody->shape(); - + std::list allRes; ModelAPI_Tools::allSubs(theResultBody, allRes); for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) { - + GeomShapePtr aShape = (*aRes)->shape(); for(std::list::iterator aResMat = it->second.begin(); aResMat != it->second.end(); ++aResMat) { if( aRes->get() && ((*aRes)->data()->name() == (*aResMat))) - { + { aSelectionList->append(theResultBody,aShape); + aSelectionList->setSelectionType(aShape->shapeTypeStr() ); break; } } @@ -325,9 +342,7 @@ void ExchangePlugin_ImportFeature::setMaterielGroup(std::shared_ptrremoveFeature(aGroupFeature); } } -} - - +} void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName) { diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h index 2875d83ab..e37ef83ec 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h @@ -139,8 +139,7 @@ private: /// Loads Naming data structure to the document void loadNamingDS(std::shared_ptr theGeomShape, std::shared_ptr theResultBody); - - // Set groups of color + // Set groups of color void setColorGroups(std::shared_ptr theResultBody); // set a group of color diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp index 281f689e3..38a1929a5 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp @@ -55,7 +55,7 @@ #include #include - +//JL_CGLB #include #include #include @@ -84,7 +84,7 @@ std::shared_ptr STEPImport(const std::string& theFileName, // Set "C" numeric locale to save numbers correctly // Kernel_Utils::Localizer loc; - + STEPControl_Reader aReader; //VSR: 16/09/09: Convert to METERS @@ -212,14 +212,15 @@ std::shared_ptr STEPImport(const std::string& theFileName, std::shared_ptr STEPImportAttributs(const std::string& theFileName, - std::shared_ptr theResultBody, - const bool anScalInterUnits, - const bool anMaterials, - const bool anColor, - std::map< std::wstring, std::list> &theMaterialShape, - std::string& theError) + std::shared_ptr theResultBody, + const bool anScalInterUnits, + const bool anMaterials, + const bool anColor, + std::map< std::wstring, + std::list> &theMaterialShape, + std::string& theError) { - + STEPControl_Reader aReader; std::shared_ptr aGeomShape(new GeomAPI_Shape); //VSR: 16/09/09: Convert to METERS @@ -286,6 +287,11 @@ std::shared_ptr STEPImportAttributs(const std::string& theFileNa return aGeomShape; } - return readAttributes(cafreader,theResultBody,anMaterials, theMaterialShape, "STEP-XCAF"); + return readAttributes(cafreader, + theResultBody, + anMaterials, + theMaterialShape, + "STEP-XCAF", + theError); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h index 9433a0a70..fd886993b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h @@ -38,11 +38,12 @@ std::shared_ptr STEPImport(const std::string& theFileName, /// Implementation of the import STEP files algorithms with Attributs (Name, Color, Materials) GEOMALGOAPI_EXPORT std::shared_ptr STEPImportAttributs(const std::string& theFileName, - std::shared_ptr theResultBody, - const bool anScalInterUnits, - const bool anMaterials, - const bool anColor, - std::map< std::wstring, std::list> &theMaterialShape, - std::string& theError); + std::shared_ptr theResultBody, + const bool anScalInterUnits, + const bool anMaterials, + const bool anColor, + std::map< std::wstring, + std::list> &theMaterialShape, + std::string& theError); #endif /* GEOMALGOAPI_STEPIMPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp index 3e2a700cf..5f7f95680 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp @@ -63,7 +63,7 @@ #include #include #include -#include +#include #include #include #include @@ -104,8 +104,10 @@ TopoDS_Shape GetShape(const Handle(Standard_Transient) &theEnti, std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, std::shared_ptr theResultBody, const bool anMaterials, - std::map< std::wstring, std::list> &theMaterialShape, - const std::string &format) + std::map< std::wstring, + std::list> &theMaterialShape, + const std::string &format, + std::string& theError) { // dummy XCAF Application to handle the STEP XCAF Document Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication(); @@ -129,11 +131,10 @@ std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, setShapeAttributes(shapeTool, colorTool, materialTool, mainLabel, TopLoc_Location(),theResultBody,theMaterialShape,false); - - std::shared_ptr ageom = setgeom(shapeTool,mainLabel); - - STEPControl_Reader aReader = reader.ChangeReader(); - + std::shared_ptr ageom = setgeom(shapeTool,mainLabel,theError); + + STEPControl_Reader aReader = reader.ChangeReader(); + // BEGIN: reading materials of sub-shapes from file if ( anMaterials ) { @@ -156,11 +157,12 @@ std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, } } - return ageom; + return ageom; } std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const TDF_Label &label) + const TDF_Label &label, + std::string& theError) { BRep_Builder B; TopoDS_Compound compound; @@ -181,7 +183,6 @@ std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeToo } else { for (Standard_Integer i=1; iGetShape(frshapes.Value(i)); - TDF_Label aLabel = shapeTool->FindShape(S, Standard_False); if ( (!aLabel.IsNull()) && (shapeTool->IsShape(aLabel)) ) { if (shapeTool->IsFree(aLabel) ) { @@ -189,12 +190,28 @@ std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeToo continue; } else { - B.Add(compound, S); + if (!shapeTool->IsReference(aLabel) ){ + for(TDF_ChildIterator it(aLabel); it.More(); it.Next()) { + B.Add(compound, shapeTool->GetShape(it.Value()) ); + } + }else{ + B.Add(compound, S); + } } } } } + TopoDS_Shape shape = compound; + // Check if any BRep entity has been read, there must be at least a vertex + if ( !TopExp_Explorer( shape, TopAbs_VERTEX ).More() ) + { + theError = "No geometrical data in the imported file."; + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape()); + return aGeomShape; + } + aGeomShape->setImpl(new TopoDS_Shape(shape)); return aGeomShape; } @@ -206,7 +223,8 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, const TDF_Label &label, const TopLoc_Location &loc, std::shared_ptr theResultBody, - std::map< std::wstring, std::list> &theMaterialShape, + std::map< std::wstring, + std::list> &theMaterialShape, bool isRef) { std::wstring shapeName; @@ -217,7 +235,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, shapeName = Locale::Convert::toWString(TCollection_AsciiString(name).ToCString()) ; } - + TopLoc_Location partLoc = loc; Handle(XCAFDoc_Location) l; if(label.FindAttribute(XCAFDoc_Location::GetID(), l)) { @@ -233,7 +251,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, setShapeAttributes( shapeTool, colorTool, materialTool, ref, partLoc,theResultBody,theMaterialShape,true); } - + if( shapeTool->IsSimpleShape(label) && (isRef || shapeTool->IsFree(label))) { TopoDS_Shape shape = shapeTool->GetShape(label); @@ -263,12 +281,11 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, if(materialTool->GetMaterial(label, matName, matDescription, matDensity, matDensName, matDensValType)) { - std::wstring nameMaterial = Locale::Convert::toWString(matName->ToCString()); - + std::wstring nameMaterial = Locale::Convert::toWString(matName->ToCString()); + theMaterialShape[nameMaterial].push_back(shapeName); } - Quantity_Color col; if(colorTool->GetColor(label, XCAFDoc_ColorGen, col)) { double r = col.Red(), g = col.Green(), b = col.Blue(); @@ -295,7 +312,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, double r = col.Red(), g = col.Green(), b = col.Blue(); TopoDS_Face face = TopoDS::Face(xp2.Current()); std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - std::wstringstream aNameFace; + std::wstringstream aNameFace; TopoDS_Shape shapeface = xp2.Current(); if (!loc.IsIdentity()){ shapeface.Move(loc); @@ -315,7 +332,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, colorTool->GetColor(xp1.Current(), XCAFDoc_ColorCurv, col)) { double r = col.Red(), g = col.Green(), b = col.Blue(); std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - std::wstringstream aNameEdge; + std::wstringstream aNameEdge; aNameEdge << L"Edge_"<< shapeName; aShapeGeom->setImpl(new TopoDS_Shape(xp1.Current() )); theResultBody->addShapeColor( @@ -326,9 +343,9 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, } } else { - int indiceChild = 1; + int indiceChild = 1; - if (!shapeTool->IsReference(label)){ + if (!shapeTool->IsReference(label) ){ TopoDS_Shape shape = shapeTool->GetShape(label); std::shared_ptr aShapeGeom(new GeomAPI_Shape); @@ -338,7 +355,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, aShapeGeom->setImpl(new TopoDS_Shape(shape)); shapeName = theResultBody->addShapeName(aShapeGeom, shapeName); } - for(TDF_ChildIterator it(label); it.More(); it.Next()) { + for(TDF_ChildIterator it(label); it.More(); it.Next()) { setShapeAttributes( shapeTool, colorTool, materialTool, it.Value(), partLoc,theResultBody,theMaterialShape, isRef); @@ -428,7 +445,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, std::shared_ptr aShapeGeom(new GeomAPI_Shape); aShapeGeom->setImpl(new TopoDS_Shape(aSub)); std::wstring nom = theResultBody->findShapeName(aShapeGeom); - std::wstring matName= Locale::Convert::toWString(aMatName->ToCString()); + std::wstring matName= Locale::Convert::toWString(aMatName->ToCString()); theMaterialShape[matName].push_back(nom); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h index 2955a5308..4e2720c40 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h @@ -21,7 +21,7 @@ #define GEOMALGOAPI_STEPIMPORTXCAF_H_ #include -#include +#include #include #include @@ -39,15 +39,17 @@ #include #include - // read Attributs of step file + // read Attributs of step file GEOMALGOAPI_EXPORT std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, - std::shared_ptr theResultBody, + std::shared_ptr theResultBody, const bool anMaterials, - std::map< std::wstring, std::list> &theMaterialShape, - const std::string &format); - // read attributs for label - GEOMALGOAPI_EXPORT + std::map< std::wstring, + std::list> &theMaterialShape, + const std::string &format, + std::string& theError); + // read attributs for label + GEOMALGOAPI_EXPORT void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, const Handle(XCAFDoc_ColorTool) &colorTool, const Handle(XCAFDoc_MaterialTool) &materialTool, @@ -57,13 +59,14 @@ std::map< std::wstring, std::list> &theMaterialShape, bool isRef); -// read geometry -GEOMALGOAPI_EXPORT +// read geometry +GEOMALGOAPI_EXPORT std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const TDF_Label &label); + const TDF_Label &label, + std::string& theError); // store Materiel for theShapeLabel in the map theMaterialShape -GEOMALGOAPI_EXPORT +GEOMALGOAPI_EXPORT void StoreMaterial( std::shared_ptr theResultBody, const Handle(Standard_Transient) &theEnti, const TopTools_IndexedMapOfShape &theIndices, diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 63380e3e2..a5b5134ae 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -1274,7 +1274,9 @@ std::shared_ptr Model_Objects::createConstruction( } std::shared_ptr Model_Objects::createBody( - const std::shared_ptr& theFeatureData, const int theIndex,const std::wstring& theNameShape ) + const std::shared_ptr& theFeatureData, + const int theIndex, + const std::wstring& theNameShape ) { TDF_Label aLab = resultLabel(theFeatureData, theIndex); TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str()); diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index fe3811543..49ba223b0 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -220,7 +220,7 @@ class Model_Objects //! Initializes the data fields of the feature void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag); - + //! Allows to store the result in the data tree of the document //! (attaches 'data' of result to tree) void storeResult(std::shared_ptr theFeatureData, diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 74b932c81..f83c96fed 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -238,17 +238,18 @@ void Model_ResultBody::updateConcealment() void Model_ResultBody::addShapeColor( const std::wstring& theName,std::vector& color) { if( myColorsShape.find(theName) == myColorsShape.end()) - myColorsShape[ theName ] = color; + myColorsShape[ theName ] = color; } -std::wstring Model_ResultBody::addShapeName(std::shared_ptr theshape,const std::wstring& theName ){ +std::wstring Model_ResultBody::addShapeName(std::shared_ptr theshape, + const std::wstring& theName ){ - int indice = 1; - std::wstringstream aName; + int indice = 1; + std::wstringstream aName; aName << theName; while(myNamesShape.find(aName.str()) != myNamesShape.end() ){ aName.str(L""); - aName << theName << L"__" << indice; + aName << theName << L"__" << indice; indice++; } myNamesShape[ aName.str() ] = theshape; @@ -259,26 +260,28 @@ std::wstring Model_ResultBody::addShapeName(std::shared_ptr thesh std::wstring Model_ResultBody::findShapeName(std::shared_ptr theshape){ TopoDS_Shape aShape = theshape->impl(); - for (std::map< std::wstring, std::shared_ptr >::iterator it = myNamesShape.begin(); + for (std::map< std::wstring, std::shared_ptr >::iterator it = + myNamesShape.begin(); it != myNamesShape.end(); ++it) - { + { TopoDS_Shape curSelectedShape = (*it).second->impl(); if( (aShape.IsSame(curSelectedShape))) { return (*it).first; } - } return L"material not found" ; } -void Model_ResultBody::setShapeName(std::map< std::wstring, std::shared_ptr > &theshapename, - std::map< std::wstring, std::vector> & theColorsShape) +void Model_ResultBody::setShapeName( + std::map< std::wstring, std::shared_ptr > &theshapename, + std::map< std::wstring, std::vector> & theColorsShape) { myNamesShape = theshapename; myColorsShape = theColorsShape; } + void Model_ResultBody::clearShapeNameAndColor(){ myNamesShape.clear(); myColorsShape.clear(); @@ -314,10 +317,11 @@ void Model_ResultBody::updateSubs(const std::shared_ptr& theThisS if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result std::wstring thenameshape = L""; // find shape name read - for (std::map< std::wstring, std::shared_ptr >::iterator it = myNamesShape.begin(); + for (std::map< std::wstring, std::shared_ptr >::iterator it = + myNamesShape.begin(); it != myNamesShape.end(); ++it) - { + { TopoDS_Shape curSelectedShape = (*it).second->impl(); if( !(aShapesIter.Value().IsSame(curSelectedShape))) continue; thenameshape = (*it).first; @@ -325,10 +329,11 @@ void Model_ResultBody::updateSubs(const std::shared_ptr& theThisS } aSub = anObjects->createBody(this->data(), aSubIndex,thenameshape); //finf color read - std::map< std::wstring, std::vector>::iterator itColor = myColorsShape.find(thenameshape); + std::map< std::wstring, std::vector>::iterator itColor = + myColorsShape.find(thenameshape); if(itColor != myColorsShape.end()){ ModelAPI_Tools::setColor(aSub,(*itColor).second); - } + } aSub->setShapeName(myNamesShape,myColorsShape); mySubs.push_back(aSub); mySubsMap[aSub] = int(mySubs.size() - 1); @@ -336,7 +341,7 @@ void Model_ResultBody::updateSubs(const std::shared_ptr& theThisS aSub->ModelAPI_ResultBody::setIsConcealed(true); std::dynamic_pointer_cast(aSub)->updateConcealment(); } - + } else { // just update shape of this result aSub = mySubs[aSubIndex]; } diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index fe3987642..b23aa1ac4 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -135,21 +135,24 @@ protected: friend class Model_Objects; - // Add shape Name for read shape in step file + // Add shape Name for read shape in step file std::wstring addShapeName(std::shared_ptr,const std::wstring& theName) override; - // Add color for shape Name read shape in step file + // Add color for shape Name read shape in step file void addShapeColor( const std::wstring& theName,std::vector& color) override; - // Set the map of name and color read shape in step file - void setShapeName(std::map< std::wstring, std::shared_ptr > &theshapename,std::map< std::wstring, std::vector> & theColorsShape) override; + // Set the map of name and color read shape in step file + void setShapeName(std::map< std::wstring, + std::shared_ptr > &theshapename, + std::map< std::wstring, + std::vector> & theColorsShape) override; // find the name of shapp read in step file std::wstring findShapeName(std::shared_ptr theshape) override; // Clear the map of name and color read shape in step file void clearShapeNameAndColor() override; - - // map with the name read in step file and shape + + // map with the name read in step file and shape std::map< std::wstring, std::shared_ptr > myNamesShape; - // map with the name contruct and color read - std::map< std::wstring, std::vector> myColorsShape; + // map with the name contruct and color read + std::map< std::wstring, std::vector> myColorsShape; }; diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index deefff6c1..7b7876165 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -117,7 +117,6 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES Config GeomAPI - Locale ${OpenCASCADE_ApplicationFramework_LIBRARIES} ) SET(CMAKE_SWIG_FLAGS -threads -w325,321,362,383,302,403,451,473) @@ -270,6 +269,4 @@ ADD_UNIT_TESTS(TestConstants.py Test19707.py Test19726.py Test19912.py - Test19932.py - Test19989.py )