From: Jérôme Date: Fri, 23 Oct 2020 15:20:32 +0000 (+0200) Subject: Documentation, refactoring and translation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed7d6af345bc5599ea7a8c8f69804de82868c80e;p=modules%2Fshaper.git Documentation, refactoring and translation --- diff --git a/src/ExchangeAPI/ExchangeAPI_Import.cpp b/src/ExchangeAPI/ExchangeAPI_Import.cpp index 70761000b..13af1b262 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Import.cpp @@ -29,7 +29,6 @@ #include #include #include - //-------------------------------------------------------------------------------------- #include @@ -68,17 +67,17 @@ ExchangeAPI_Import::~ExchangeAPI_Import() //-------------------------------------------------------------------------------------- void ExchangeAPI_Import::setParameters(const std::string & theFilePath, - const bool anScalInterUnits, - const bool anMaterials, - const bool anColor) + const bool theScalInterUnits, + const bool theMaterials, + const bool theColor) { fillAttribute(theFilePath, mystepfilePath); fillAttribute("STEP", feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID())); - fillAttribute(anScalInterUnits, + fillAttribute(theScalInterUnits, feature()->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())); - fillAttribute(anMaterials, + fillAttribute(theMaterials, feature()->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())); - fillAttribute(anColor, + fillAttribute(theColor, feature()->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())); execute(); } @@ -88,12 +87,8 @@ void ExchangeAPI_Import::setFilePath(const std::string & theFilePath) { fillAttribute(theFilePath, myfilePath); std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFilePath); - if (anExtension == "STEP" || anExtension == "STP") { - setParameters(theFilePath,true,false,false); - }else{ - fillAttribute(anExtension, feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID())); - execute(); - } + fillAttribute(anExtension, feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID())); + execute(); } //-------------------------------------------------------------------------------------- @@ -161,13 +156,13 @@ ImportPtr addImport( ImportPtr addImportStep( const std::shared_ptr & thePart, const std::string & theFilePath, - const bool anScalInterUnits, - const bool anMaterials, - const bool anColor ) + const bool theScalInterUnits, + const bool theMaterials, + const bool theColor ) { std::shared_ptr aFeature = thePart->addFeature(ExchangeAPI_Import::ID()); return ImportPtr(new ExchangeAPI_Import(aFeature, theFilePath, - anScalInterUnits, anMaterials, anColor)); + theScalInterUnits, theMaterials, theColor)); } void importPart(const std::shared_ptr & thePart, diff --git a/src/ExchangePlugin/ExchangePlugin_Import.h b/src/ExchangePlugin/ExchangePlugin_Import.h index 38d3e05e7..2babe4fbe 100644 --- a/src/ExchangePlugin/ExchangePlugin_Import.h +++ b/src/ExchangePlugin/ExchangePlugin_Import.h @@ -102,7 +102,7 @@ class ExchangePlugin_Import : public ModelAPI_Feature /// attribute name of step colors inline static const std::string& STEP_COLORS_ID() { - static const std::string MY_STEP_COLORS_ID("step_colours"); + static const std::string MY_STEP_COLORS_ID("step_colors"); return MY_STEP_COLORS_ID; } /// Default constructor diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 5419e5ec8..0535c3888 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -106,7 +106,6 @@ void ExchangePlugin_ImportFeature::initAttributes() getKind(), ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory( getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID()); - } /* @@ -133,11 +132,11 @@ void ExchangePlugin_ImportFeature::execute() } std::shared_ptr ExchangePlugin_ImportFeature::createResultBody( - std::shared_ptr aGeomShape) + std::shared_ptr theGeomShape) { std::shared_ptr aResultBody = document()->createBody(data()); //LoadNamingDS of the imported shape - loadNamingDS(aGeomShape, aResultBody); + loadNamingDS(theGeomShape, aResultBody); return aResultBody; } @@ -160,7 +159,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName); data()->setName(Locale::Convert::toWString(anObjectName)); - ResultBodyPtr result = document()->createBody(data()); + ResultBodyPtr aResult = document()->createBody(data()); bool anColorGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())->value(); bool anMaterialsGroupSelected = @@ -174,7 +173,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) try{ - result->clearShapeNameAndColor(); + aResult->clearShapeNameAndColor(); // Process groups/fields std::shared_ptr aRefListOfGroups = std::dynamic_pointer_cast(data()->attribute(FEATURES_ID())); @@ -188,14 +187,14 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) document()->removeFeature(aFeature); } - aGeomShape = STEPImportAttributs(theFileName, result, anScalInterUnits, + aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits, anMaterialsGroupSelected, anColorGroupSelected, theMaterialShape,anError); } catch (OSD_Exception& e) { - //Try to load STEP file without colors... - aGeomShape = STEPImport(theFileName, anExtension,anScalInterUnits,anError); + //Try to load STEP file without colors... + aGeomShape = STEPImport(theFileName, anExtension,anScalInterUnits,anError); } } else if (anExtension == "IGES" || anExtension == "IGS") { aGeomShape = IGESImport(theFileName, anExtension, anError); @@ -211,20 +210,20 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) // Pass the results into the model - loadNamingDS(aGeomShape, result); + loadNamingDS(aGeomShape, aResult); // create color group if (anColorGroupSelected) { - setColorGroups(result); + setColorGroups(aResult); } // create Materiel group if (anMaterialsGroupSelected){ - setMaterielGroup(result,theMaterialShape); + setMaterielGroup(aResult,theMaterialShape); } - setResult(result); + setResult(aResult); } @@ -232,16 +231,15 @@ void ExchangePlugin_ImportFeature::setColorGroups( std::shared_ptr theResultBody) { std::vector aColor; - int indice = 1; + int anIndice = 1; std::list< std::vector > aColorsRead; - ModelAPI_Tools::getColor(theResultBody, aColor); if (!aColor.empty() ){ - std::wstringstream colorName; - colorName< theResultBody, - std::vector &theColor, - const std::wstring& theName ) +void ExchangePlugin_ImportFeature::setColorGroup( + std::shared_ptr theResultBody, + std::vector &theColor, + const std::wstring& theName ) { std::vector aColor; std::shared_ptr aGroupFeature = addFeature("Group"); @@ -311,17 +310,15 @@ void ExchangePlugin_ImportFeature::setColorGroup(std::shared_ptr theResultBody, - std::map< std::wstring, - std::list> &theMaterialShape) + std::shared_ptr theResultBody, + std::map< std::wstring,std::list> &theMaterialShape) { - int indice = 1; - std::map< std::wstring, std::list>::iterator it; - for( it = theMaterialShape.begin(); it != theMaterialShape.end(); ++it) { + std::map< std::wstring, std::list>::iterator anIt; + for( anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) { std::shared_ptr aGroupFeature = addFeature("Group"); // group name - aGroupFeature->data()->setName((*it).first); + aGroupFeature->data()->setName((*anIt).first); // fill selection AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list"); @@ -332,8 +329,8 @@ void ExchangePlugin_ImportFeature::setMaterielGroup( 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) { + for(std::list::iterator aResMat = anIt->second.begin(); + aResMat != anIt->second.end(); ++aResMat) { if( aRes->get() && ((*aRes)->data()->name() == (*aResMat))) { aSelectionList->append(theResultBody,aShape); diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h index e37ef83ec..93d551bf5 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h @@ -83,7 +83,7 @@ class ExchangePlugin_ImportFeature : public ModelAPI_CompositeFeature /// attribute name of step colors inline static const std::string& STEP_COLORS_ID() { - static const std::string MY_STEP_COLORS_ID("step_colours"); + static const std::string MY_STEP_COLORS_ID("step_colors"); return MY_STEP_COLORS_ID; } /// Default constructor diff --git a/src/ExchangePlugin/ExchangePlugin_msg_fr.ts b/src/ExchangePlugin/ExchangePlugin_msg_fr.ts index 110053a1d..72f1663ec 100644 --- a/src/ExchangePlugin/ExchangePlugin_msg_fr.ts +++ b/src/ExchangePlugin/ExchangePlugin_msg_fr.ts @@ -295,9 +295,13 @@ Importer - Import a file - Importer un fichier + Create groups from + créer des groupes à partir + + Materials + Matériels + Import:file_path @@ -306,7 +310,33 @@ Importer un fichier - + + Import:step_file_path + + Import file + Importer un fichier + + + + Import:step_scale_inter_units + + Scale to International System of Units + Mettre àl'échelle du système international d'unités + + + Import:step_materials + + Materials + Matériels + + + + Import:step_materials + + Colors + Couleurs + + ImportMacro @@ -318,6 +348,10 @@ Importer un fichier + + Create groups from + créer des groupes à partir + ImportMacro:target_part @@ -325,6 +359,33 @@ Importer vers + + ImportMacro:step_target_part + + Import to + Importer vers + + + + ImportMacro:step_scale_inter_units + + Scale to International System of Units + Mettre àl'échelle du système international d'unités + + + Import:step_materials + + Materials + Matériels + + + + Import:step_materials + + Colors + Couleurs + + ImportMacro:file_path @@ -332,6 +393,14 @@ Fichier à importer + + ImportMacro:step_file_path + + Import file + Importer un fichier + + + ImportMacro:file_path:ExchangePlugin_ImportFormat diff --git a/src/ExchangePlugin/doc/TUI_importFeature.rst b/src/ExchangePlugin/doc/TUI_importFeature.rst index 69ed88ab6..af78d3d83 100644 --- a/src/ExchangePlugin/doc/TUI_importFeature.rst +++ b/src/ExchangePlugin/doc/TUI_importFeature.rst @@ -10,3 +10,13 @@ Import File :download:`Download this script ` + .. _tui_import_file_step: + +Import STEP File +================ + +.. literalinclude:: examples/importStep.py + :linenos: + :language: python + +:download:`Download this script ` \ No newline at end of file diff --git a/src/ExchangePlugin/doc/examples/importStep.py b/src/ExchangePlugin/doc/examples/importStep.py new file mode 100644 index 000000000..f6a81281a --- /dev/null +++ b/src/ExchangePlugin/doc/examples/importStep.py @@ -0,0 +1,10 @@ +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Import_1 = model.addImportStep(Part_1_doc, + "/SOURCES/SAMPLES/Shapes/Step/black_and_white.step", True, True, True) +model.do() +model.end() diff --git a/src/ExchangePlugin/doc/images/FileImportedSTEP.png b/src/ExchangePlugin/doc/images/FileImportedSTEP.png new file mode 100644 index 000000000..d4f171d81 Binary files /dev/null and b/src/ExchangePlugin/doc/images/FileImportedSTEP.png differ diff --git a/src/ExchangePlugin/doc/images/ImportSTEP.png b/src/ExchangePlugin/doc/images/ImportSTEP.png new file mode 100644 index 000000000..457d02d8b Binary files /dev/null and b/src/ExchangePlugin/doc/images/ImportSTEP.png differ diff --git a/src/ExchangePlugin/doc/images/Import_panel.png b/src/ExchangePlugin/doc/images/Import_panel.png index c22176e77..4d610af44 100644 Binary files a/src/ExchangePlugin/doc/images/Import_panel.png and b/src/ExchangePlugin/doc/images/Import_panel.png differ diff --git a/src/ExchangePlugin/doc/importFeature.rst b/src/ExchangePlugin/doc/importFeature.rst index 4692ec669..a133b2f84 100644 --- a/src/ExchangePlugin/doc/importFeature.rst +++ b/src/ExchangePlugin/doc/importFeature.rst @@ -67,6 +67,8 @@ The following property panel will be opened: **Import property panel** +The first combobox provides the list of formats avalables (BREP, XAO, IGES or STEP). + The **Import to** combobox provides the list of destinations (one of existing Parts or a new Part). In this panel it is possible to enter a file name directly or press **'...'** button and browse it with help of import file dialog box: @@ -75,7 +77,11 @@ In this panel it is possible to enter a file name directly or press **'...'** bu :align: center **Dialog box to import CAD-neutral format** - + +Import BREP, XAO, IGES +"""""""""""""""""""""" +In case of first choice the format of imported file will be defined according to file extension. + **Apply** button imports the file. **Cancel** button cancels the operation. @@ -98,3 +104,45 @@ The Result of the operation depends on the imported file content. Import of BREP file. **See Also** a sample TUI Script of :ref:`tui_import_file` operation. + + +Import STEP +""""""""""" + +In this case, the following property panel will be opened: + +.. figure:: images/ImportSTEP.png + :align: center + + **Dialog box to import file in STEP format** + + +The file name and path can be defined in **Import file** field by direct input or browsing with ‘…’ button, which opens **Import file** dialog box. +The **Import to** combobox provides the list of destinations (one of existing Parts or a new Part). +**STEP options** provide the possibility to **Scale to International System Units** as well as to create groups from **Materials** and/or **Colours** if defined in assemblies of the file to import. + +**Apply** button imports the file. + +**Cancel** button cancels the operation. + +**TUI Command**: + +.. py:function:: model.addImportStep(Part_doc, FileNameString,scalInterUnits,materials,colors) + + :param part: The current part object + :param string: A file name string. + :param scalInterUnits: True if scale to UIS + :param materials: True to create groups from materials + :param colors: True to create groups from colors + +Result +"""""" + +The Result of the operation depends on the imported file content. + +.. figure:: images/FileImportedSTEP.png + :align: center + + Import of STEP file. + +**See Also** a sample TUI Script of :ref:`tui_import_file_step` operation. diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index 275ceb69b..7ebebc844 100644 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -30,8 +30,8 @@ - diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp index 38a1929a5..5fdb7f687 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp @@ -76,7 +76,7 @@ std::shared_ptr STEPImport(const std::string& theFileName, const std::string& theFormatName, - const bool anScalInterUnits, + const bool theScalInterUnits, std::string& theError) { @@ -104,7 +104,7 @@ std::shared_ptr STEPImport(const std::string& theFileName, if (status == IFSelect_RetDone) { // Regard or not the model units - if (!anScalInterUnits) { + if (!theScalInterUnits) { // set UnitFlag to units from file TColStd_SequenceOfAsciiString anUnitLengthNames; TColStd_SequenceOfAsciiString anUnitAngleNames; @@ -213,9 +213,9 @@ 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, + const bool theScalInterUnits, + const bool theMaterials, + const bool theColor, std::map< std::wstring, std::list> &theMaterialShape, std::string& theError) @@ -236,7 +236,7 @@ std::shared_ptr STEPImportAttributs(const std::string& theFileNa if (status == IFSelect_RetDone) { // Regard or not the model units - if (!anScalInterUnits) { + if (!theScalInterUnits) { // set UnitFlag to units from file TColStd_SequenceOfAsciiString anUnitLengthNames; TColStd_SequenceOfAsciiString anUnitAngleNames; @@ -275,23 +275,22 @@ std::shared_ptr STEPImportAttributs(const std::string& theFileNa return aGeomShape; } - STEPCAFControl_Reader cafreader; - cafreader.SetColorMode(true); - cafreader.SetNameMode(true); - cafreader.SetMatMode(true); + STEPCAFControl_Reader aCafreader; + aCafreader.SetColorMode(true); + aCafreader.SetNameMode(true); + aCafreader.SetMatMode(true); - if(cafreader.ReadFile(theFileName.c_str()) != IFSelect_RetDone) { + if(aCafreader.ReadFile(theFileName.c_str()) != IFSelect_RetDone) { theError = "Wrong format of the imported file. Can't import file."; std::shared_ptr aGeomShape(new GeomAPI_Shape); aGeomShape->setImpl(new TopoDS_Shape()); return aGeomShape; } - return readAttributes(cafreader, + return readAttributes(aCafreader, theResultBody, - anMaterials, + theMaterials, theMaterialShape, - "STEP-XCAF", theError); - } +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp index f2b130775..8a465911d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp @@ -84,10 +84,10 @@ */ //============================================================================= -TopoDS_Shape GetShape(const Handle(Standard_Transient) &theEnti, - const Handle(Transfer_TransientProcess) &theTP) +TopoDS_Shape getShape(const Handle(Standard_Transient) &theEnti, + const Handle(Transfer_TransientProcess) &theTP) { - TopoDS_Shape aResult; + TopoDS_Shape aResult; Handle(Transfer_Binder) aBinder = theTP->Find(theEnti); if (aBinder.IsNull()) { @@ -101,13 +101,12 @@ 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::string& theError) +std::shared_ptr readAttributes( + STEPCAFControl_Reader &theReader, + std::shared_ptr theResultBody, + const bool theIsMaterials, + std::map< std::wstring,std::list> &theMaterialShape, + std::string& theError) { // dummy XCAF Application to handle the STEP XCAF Document Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication(); @@ -116,7 +115,7 @@ std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, dummy_app->NewDocument( TCollection_ExtendedString("MDTV-CAF"), doc); // transfer STEP/IGES into the document, and get the main label - reader.Transfer(doc); + theReader.Transfer(doc); TDF_Label mainLabel = doc->Main(); Handle_XCAFDoc_ShapeTool shapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLabel); Handle_XCAFDoc_ColorTool colorTool = XCAFDoc_DocumentTool::ColorTool(mainLabel); @@ -127,10 +126,10 @@ std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, std::shared_ptr ageom = setgeom(shapeTool,mainLabel,theError); - STEPControl_Reader aReader = reader.ChangeReader(); + STEPControl_Reader aReader = theReader.ChangeReader(); // BEGIN: reading materials of sub-shapes from file - if ( anMaterials ) + if ( theIsMaterials ) { TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(ageom->impl(), anIndices); @@ -146,58 +145,58 @@ std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, Handle(Standard_Transient) enti = Model->Value(ie); // Store materials. - StoreMaterial(theResultBody,enti, anIndices, TP, mainLabel,theMaterialShape); + storeMaterial(theResultBody,enti, anIndices, TP, mainLabel,theMaterialShape); } } } return ageom; } -std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const TDF_Label &label, +std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &theShapeTool, + const TDF_Label &theLabel, std::string& theError) { - BRep_Builder B; - TopoDS_Compound compound; - B.MakeCompound(compound); + BRep_Builder aB; + TopoDS_Compound aCompound; + aB.MakeCompound(aCompound); - TDF_LabelSequence frshapes; - shapeTool->GetShapes(frshapes); + TDF_LabelSequence aFrshapes; + theShapeTool->GetShapes(aFrshapes); std::shared_ptr aGeomShape(new GeomAPI_Shape); - if (frshapes.Length() == 0) { + if (aFrshapes.Length() == 0) { aGeomShape->setImpl(new TopoDS_Shape()); return aGeomShape; - } else if (frshapes.Length() == 1) { - TopoDS_Shape shape = shapeTool->GetShape(frshapes.Value(1)); + } else if (aFrshapes.Length() == 1) { + TopoDS_Shape shape = theShapeTool->GetShape(aFrshapes.Value(1)); aGeomShape->setImpl(new TopoDS_Shape(shape)); return aGeomShape; } 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) ) { - if (S.IsNull()) { + for (Standard_Integer i=1; iGetShape(aFrshapes.Value(i)); + TDF_Label aLabel = theShapeTool->FindShape(aS, Standard_False); + if ( (!aLabel.IsNull()) && (theShapeTool->IsShape(aLabel)) ) { + if (theShapeTool->IsFree(aLabel) ) { + if (aS.IsNull()) { continue; } else { - if (!shapeTool->IsReference(aLabel) ){ - for(TDF_ChildIterator it(aLabel); it.More(); it.Next()) { - B.Add(compound, shapeTool->GetShape(it.Value()) ); + if (!theShapeTool->IsReference(aLabel) ){ + for(TDF_ChildIterator anIt(aLabel); anIt.More(); anIt.Next()) { + aB.Add(aCompound, theShapeTool->GetShape(anIt.Value()) ); } }else{ - B.Add(compound, S); + aB.Add(aCompound, aS); } } } } } - TopoDS_Shape shape = compound; + TopoDS_Shape aShape = aCompound; // Check if any BRep entity has been read, there must be at least a vertex - if ( !TopExp_Explorer( shape, TopAbs_VERTEX ).More() ) + if ( !TopExp_Explorer( aShape, TopAbs_VERTEX ).More() ) { theError = "No geometrical data in the imported file."; std::shared_ptr aGeomShape(new GeomAPI_Shape); @@ -205,154 +204,150 @@ std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeToo return aGeomShape; } - aGeomShape->setImpl(new TopoDS_Shape(shape)); + aGeomShape->setImpl(new TopoDS_Shape(aShape)); return aGeomShape; } } -void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const Handle(XCAFDoc_ColorTool) &colorTool, - const Handle(XCAFDoc_MaterialTool) &materialTool, - const TDF_Label &label, - const TopLoc_Location &loc, - std::shared_ptr theResultBody, - std::map< std::wstring, - std::list> &theMaterialShape, - bool isRef) +void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool, + const Handle(XCAFDoc_ColorTool) &theColorTool, + const Handle(XCAFDoc_MaterialTool) &theMaterialTool, + const TDF_Label &theLabel, + const TopLoc_Location &theLoc, + std::shared_ptr theResultBody, + std::map< std::wstring,std::list> &theMaterialShape, + bool theIsRef) { - std::wstring shapeName; - Handle(TDataStd_Name) n; + std::wstring aShapeName; + Handle(TDataStd_Name) aN; - if(label.FindAttribute(TDataStd_Name::GetID(), n)) { - TCollection_ExtendedString name = n->Get(); + if(theLabel.FindAttribute(TDataStd_Name::GetID(), aN)) { + TCollection_ExtendedString aName = aN->Get(); - shapeName = Locale::Convert::toWString(TCollection_AsciiString(name).ToCString()) ; + aShapeName = Locale::Convert::toWString(TCollection_AsciiString(aName).ToCString()) ; } - TopLoc_Location partLoc = loc; - Handle(XCAFDoc_Location) l; - if(label.FindAttribute(XCAFDoc_Location::GetID(), l)) { - if(isRef) - partLoc = partLoc * l->Get(); + TopLoc_Location aPartLoc = theLoc; + Handle(XCAFDoc_Location) al; + if(theLabel.FindAttribute(XCAFDoc_Location::GetID(), al)) { + if(theIsRef) + aPartLoc = aPartLoc * al->Get(); else - partLoc = l->Get(); + aPartLoc = al->Get(); } - TDF_Label ref; - if(shapeTool->IsReference(label) && shapeTool->GetReferredShape(label, ref)) { + TDF_Label aRef; + if(theShapeTool->IsReference(theLabel) && theShapeTool->GetReferredShape(theLabel, aRef)) { - setShapeAttributes( shapeTool, colorTool, materialTool, ref, - partLoc,theResultBody,theMaterialShape,true); + setShapeAttributes( theShapeTool, theColorTool, theMaterialTool, aRef, + aPartLoc,theResultBody,theMaterialShape,true); } - if( shapeTool->IsSimpleShape(label) && (isRef || shapeTool->IsFree(label))) { + if( theShapeTool->IsSimpleShape(theLabel) && (theIsRef || theShapeTool->IsFree(theLabel))) { - TopoDS_Shape shape = shapeTool->GetShape(label); + TopoDS_Shape aShape = theShapeTool->GetShape(theLabel); std::shared_ptr aShapeGeom(new GeomAPI_Shape); - if (!loc.IsIdentity()){ - shape.Move(loc); + if (!theLoc.IsIdentity()){ + aShape.Move(theLoc); } - aShapeGeom->setImpl(new TopoDS_Shape(shape)); - shapeName = theResultBody->addShapeName(aShapeGeom, shapeName); + aShapeGeom->setImpl(new TopoDS_Shape(aShape)); + aShapeName = theResultBody->addShapeName(aShapeGeom, aShapeName); - shape.Location(isRef ? loc : partLoc); - int dim = - (shape.ShapeType() == TopAbs_VERTEX) ? + aShape.Location(theIsRef ? theLoc : aPartLoc); + int aDim = + (aShape.ShapeType() == TopAbs_VERTEX) ? 0 : - (shape.ShapeType() == TopAbs_EDGE || shape.ShapeType() == TopAbs_WIRE) ? + (aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE) ? 1 : - (shape.ShapeType() == TopAbs_FACE || - shape.ShapeType() == TopAbs_SHELL) ? 2 :3; + (aShape.ShapeType() == TopAbs_FACE || + aShape.ShapeType() == TopAbs_SHELL) ? 2 :3; - Handle(TCollection_HAsciiString) matName; - Handle(TCollection_HAsciiString) matDescription; - Standard_Real matDensity; - Handle(TCollection_HAsciiString) matDensName; - Handle(TCollection_HAsciiString) matDensValType; + Handle(TCollection_HAsciiString) aMatName; + Handle(TCollection_HAsciiString) aMatDescription; + Standard_Real aMatDensity; + Handle(TCollection_HAsciiString) aMatDensName; + Handle(TCollection_HAsciiString) aMatDensValType; - if(materialTool->GetMaterial(label, matName, matDescription, matDensity, - matDensName, matDensValType)) { - std::wstring nameMaterial = Locale::Convert::toWString(matName->ToCString()); + if(theMaterialTool->GetMaterial(theLabel, aMatName, aMatDescription, aMatDensity, + aMatDensName, aMatDensValType)) { + std::wstring aNameMaterial = Locale::Convert::toWString(aMatName->ToCString()); - theMaterialShape[nameMaterial].push_back(shapeName); + theMaterialShape[aNameMaterial].push_back(aShapeName); } - Quantity_Color col; - if(colorTool->GetColor(label, XCAFDoc_ColorGen, col)) { - double r = col.Red(), g = col.Green(), b = col.Blue(); + Quantity_Color aCol; + if(theColorTool->GetColor(theLabel, XCAFDoc_ColorGen, aCol)) { + double r = aCol.Red(), g = aCol.Green(), b = aCol.Blue(); std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - theResultBody->addShapeColor(shapeName, ColRGB); + theResultBody->addShapeColor(aShapeName, ColRGB); } - else if(colorTool->GetColor(label, XCAFDoc_ColorSurf, col)) { - double r = col.Red(), g = col.Green(), b = col.Blue(); - std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - theResultBody->addShapeColor(shapeName, ColRGB); + else if(theColorTool->GetColor(theLabel, XCAFDoc_ColorSurf, aCol)) { + double r = aCol.Red(), g = aCol.Green(), b = aCol.Blue(); + std::vector aColRGB = {int(r*255),int(g*255),int(b*255)}; + theResultBody->addShapeColor(aShapeName, aColRGB); } - else if(colorTool->GetColor(label, 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)}; - theResultBody->addShapeColor(shapeName, ColRGB); + else if(theColorTool->GetColor(theLabel, XCAFDoc_ColorCurv, aCol)) { + double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue(); + std::vector aColRGB = {int(aR*255),int(aG*255),int(aB*255)}; + theResultBody->addShapeColor(aShapeName, aColRGB); } // check explicit coloring of boundary entities - if(dim == 3) { - TopExp_Explorer xp2(shape, TopAbs_FACE); - while(xp2.More()) { - if(colorTool->GetColor(xp2.Current(), XCAFDoc_ColorGen, col) || - colorTool->GetColor(xp2.Current(), XCAFDoc_ColorSurf, col) || - colorTool->GetColor(xp2.Current(), XCAFDoc_ColorCurv, col)) { - 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)}; + if(aDim == 3) { + TopExp_Explorer aXp2(aShape, TopAbs_FACE); + while(aXp2.More()) { + if(theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorGen, aCol) || + theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorSurf, aCol) || + theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorCurv, aCol)) { + double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue(); + TopoDS_Face aFace = TopoDS::Face(aXp2.Current()); + std::vector aColRGB = {int(aR*255),int(aG*255),int(aB*255)}; std::wstringstream aNameFace; - TopoDS_Shape shapeface = xp2.Current(); - if (!loc.IsIdentity()){ - shapeface.Move(loc); + TopoDS_Shape aShapeface = aXp2.Current(); + if (!theLoc.IsIdentity()){ + aShapeface.Move(theLoc); } - aShapeGeom->setImpl(new TopoDS_Shape(shapeface)); + aShapeGeom->setImpl(new TopoDS_Shape(aShapeface)); theResultBody->addShapeColor( - theResultBody->addShapeName(aShapeGeom , aNameFace.str()), ColRGB); + theResultBody->addShapeName(aShapeGeom , aNameFace.str()), aColRGB); } - xp2.Next(); + aXp2.Next(); } } - if(dim == 2) { - TopExp_Explorer xp1(shape, TopAbs_EDGE); - while(xp1.More()) { - if(colorTool->GetColor(xp1.Current(), XCAFDoc_ColorGen, col) || - colorTool->GetColor(xp1.Current(), XCAFDoc_ColorSurf, col) || - 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)}; + if(aDim == 2) { + TopExp_Explorer aXp1(aShape, TopAbs_EDGE); + while(aXp1.More()) { + if(theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorGen, aCol) || + theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorSurf, aCol) || + theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorCurv, aCol)) { + double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue(); + std::vector aColRGB = {int(aR*255),int(aG*255),int(aB*255)}; std::wstringstream aNameEdge; - aNameEdge << L"Edge_"<< shapeName; - aShapeGeom->setImpl(new TopoDS_Shape(xp1.Current() )); + aNameEdge << L"Edge_"<< aShapeName; + aShapeGeom->setImpl(new TopoDS_Shape(aXp1.Current() )); theResultBody->addShapeColor( - theResultBody->addShapeName(aShapeGeom , aNameEdge.str()), ColRGB); + theResultBody->addShapeName(aShapeGeom , aNameEdge.str()), aColRGB); } - xp1.Next(); + aXp1.Next(); } } } else { - int indiceChild = 1; - - if (!shapeTool->IsReference(label) ){ - TopoDS_Shape shape = shapeTool->GetShape(label); + if (!theShapeTool->IsReference(theLabel) ){ + TopoDS_Shape aShape = theShapeTool->GetShape(theLabel); std::shared_ptr aShapeGeom(new GeomAPI_Shape); - if (!loc.IsIdentity()){ - shape.Move(loc); + if (!theLoc.IsIdentity()){ + aShape.Move(theLoc); } - aShapeGeom->setImpl(new TopoDS_Shape(shape)); - shapeName = theResultBody->addShapeName(aShapeGeom, shapeName); + aShapeGeom->setImpl(new TopoDS_Shape(aShape)); + aShapeName = theResultBody->addShapeName(aShapeGeom, aShapeName); } - for(TDF_ChildIterator it(label); it.More(); it.Next()) { + for(TDF_ChildIterator anIt(theLabel); anIt.More(); anIt.Next()) { - setShapeAttributes( shapeTool, colorTool, materialTool, - it.Value(), partLoc,theResultBody,theMaterialShape, isRef); - indiceChild++; + setShapeAttributes( theShapeTool, theColorTool, theMaterialTool, + anIt.Value(), aPartLoc,theResultBody,theMaterialShape, theIsRef); } } } @@ -364,7 +359,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, */ //============================================================================= - void StoreMaterial( std::shared_ptr theResultBody, + void storeMaterial( std::shared_ptr theResultBody, const Handle(Standard_Transient) &theEnti, const TopTools_IndexedMapOfShape &theIndices, const Handle(Transfer_TransientProcess) &theTP, @@ -405,10 +400,10 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, Handle(StepRepr_Representation) aRepr = aPDR->UsedRepresentation(); if(aRepr.IsNull() == Standard_False) { - Standard_Integer ir; + Standard_Integer anIr; - for(ir = 1; ir <= aRepr->NbItems(); ir++) { - Handle(StepRepr_RepresentationItem) aRI = aRepr->ItemsValue(ir); + for(anIr = 1; anIr <= aRepr->NbItems(); anIr++) { + Handle(StepRepr_RepresentationItem) aRI = aRepr->ItemsValue(anIr); Handle(StepRepr_DescriptiveRepresentationItem) aDRI = Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aRI); @@ -421,7 +416,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, if (aShape.IsNull()) { //Get the shape. - aShape = GetShape(aProdDef, theTP); + aShape = getShape(aProdDef, theTP); if (aShape.IsNull()) { return; } @@ -429,17 +424,17 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, // as PRODUCT can be included in the main shape // several times, we look here for all iclusions. - Standard_Integer isub, nbSubs = theIndices.Extent(); + Standard_Integer anISub, aNbSubs = theIndices.Extent(); - for (isub = 1; isub <= nbSubs; isub++) { - TopoDS_Shape aSub = theIndices.FindKey(isub); + for (anISub = 1; anISub <= aNbSubs; anISub++) { + TopoDS_Shape aSub = theIndices.FindKey(anISub); if (aSub.IsPartner(aShape)) { 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()); - theMaterialShape[matName].push_back(nom); + std::wstring aNom = theResultBody->findShapeName(aShapeGeom); + std::wstring aMName= Locale::Convert::toWString(aMatName->ToCString()); + theMaterialShape[aMName].push_back(aNom); } } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h index 4e2720c40..04d4cb721 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h @@ -41,37 +41,36 @@ // read Attributs of step file GEOMALGOAPI_EXPORT - 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::string& theError); - // read attributs for label + std::shared_ptr readAttributes( + STEPCAFControl_Reader &theReader, + std::shared_ptr theResultBody, + const bool theMaterials, + std::map< std::wstring,std::list> &theMaterialShape, + 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, - const TDF_Label &label, - const TopLoc_Location &loc, + void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool, + const Handle(XCAFDoc_ColorTool) &theColorTool, + const Handle(XCAFDoc_MaterialTool) &TheMaterialTool, + const TDF_Label &theLabel, + const TopLoc_Location &theLoc, std::shared_ptr theResultBody, std::map< std::wstring, std::list> &theMaterialShape, - bool isRef); + bool theIsRef); // read geometry GEOMALGOAPI_EXPORT std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const TDF_Label &label, - std::string& theError); + const TDF_Label &theLabel, + std::string& theError); // store Materiel for theShapeLabel in the map theMaterialShape GEOMALGOAPI_EXPORT -void StoreMaterial( std::shared_ptr theResultBody, - const Handle(Standard_Transient) &theEnti, - const TopTools_IndexedMapOfShape &theIndices, - const Handle(Transfer_TransientProcess) &theTP, - const TDF_Label &theShapeLabel, +void storeMaterial( std::shared_ptr theResultBody, + const Handle(Standard_Transient) &theEnti, + const TopTools_IndexedMapOfShape &theIndices, + const Handle(Transfer_TransientProcess) &theTP, + const TDF_Label &theShapeLabel, std::map< std::wstring, std::list> &theMaterialShape ); #endif /* GEOMALGOAPI_STEPIMPORTXCAF_H_ */