From: mpv Date: Wed, 18 Mar 2015 07:38:24 +0000 (+0300) Subject: Make same naming in the data model and in XML of types of shapes. Make Extrusion... X-Git-Tag: V_1.1.0~112^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b04995d04df6376eb662cd2ce52b64f59573a334;p=modules%2Fshaper.git Make same naming in the data model and in XML of types of shapes. Make Extrusion selection type "FACE" by default that allows to simplify tests a little. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index ad23adbcb..c84c00702 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -28,7 +28,11 @@ FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion() void FeaturesPlugin_Extrusion::initAttributes() { - data()->addAttribute(FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelectionList::type()); + AttributeSelectionListPtr aSelection = + std::dynamic_pointer_cast(data()->addAttribute( + FeaturesPlugin_Extrusion::LIST_ID(), ModelAPI_AttributeSelectionList::type())); + // extrusion works with faces always + aSelection->setSelectionType("FACE"); data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type()); data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type()); } diff --git a/src/FeaturesPlugin/Test/TestBoolean.py b/src/FeaturesPlugin/Test/TestBoolean.py index 1e6aa1b88..19158fa53 100644 --- a/src/FeaturesPlugin/Test/TestBoolean.py +++ b/src/FeaturesPlugin/Test/TestBoolean.py @@ -95,8 +95,6 @@ for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]: origin, dirX, dirY, norm, aSketchEdges, aSketchFaces) # Create extrusion on them anExtrusionFt = aPart.addFeature("Extrusion") - # selection type FACE=4 - anExtrusionFt.selectionList("base").setSelectionType(4) anExtrusionFt.selectionList("base").append( aSketchResult, aSketchFaces[0]) anExtrusionFt.real("size").setValue(50) diff --git a/src/FeaturesPlugin/Test/TestExtrusion.py b/src/FeaturesPlugin/Test/TestExtrusion.py index 18595e23b..f24ee3ce6 100644 --- a/src/FeaturesPlugin/Test/TestExtrusion.py +++ b/src/FeaturesPlugin/Test/TestExtrusion.py @@ -73,7 +73,6 @@ aSession.startOperation() anExtrusionFt = aPart.addFeature("Extrusion") assert (anExtrusionFt.getKind() == "Extrusion") # selection type FACE=4 -anExtrusionFt.selectionList("base").setSelectionType(4) anExtrusionFt.selectionList("base").append( aSketchResult, aSketchFaces[0]) anExtrusionFt.real("size").setValue(50) diff --git a/src/FeaturesPlugin/Test/TestGroup.py b/src/FeaturesPlugin/Test/TestGroup.py index 5a9ef243a..9692c2cdd 100644 --- a/src/FeaturesPlugin/Test/TestGroup.py +++ b/src/FeaturesPlugin/Test/TestGroup.py @@ -66,8 +66,6 @@ GeomAlgoAPI_SketchBuilder.createFaces( origin, dirX, dirY, norm, aSketchEdges, aSketchFaces) # Create extrusion on them anExtrusionFt = aPart.addFeature("Extrusion") -# selection type FACE=4 -anExtrusionFt.selectionList("base").setSelectionType(4) anExtrusionFt.selectionList("base").append( aSketchResult, aSketchFaces[0]) anExtrusionFt.real("size").setValue(50) @@ -83,8 +81,7 @@ anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult()) aSession.startOperation() aGroupFeature = aSession.activeDocument().addFeature("Group") aSelectionListAttr = aGroupFeature.selectionList("group_list") -topAbs_EdgeType = 6 -aSelectionListAttr.setSelectionType(topAbs_EdgeType) +aSelectionListAttr.setSelectionType("edge") aSelectionListAttr.append("Extrusion_1/LateralFace_3|Extrusion_1/LateralFace_1") aSession.finishOperation() #========================================================================= diff --git a/src/FeaturesPlugin/Test/TestMultiBoolean.py b/src/FeaturesPlugin/Test/TestMultiBoolean.py index 6d26957ea..594c3af72 100644 --- a/src/FeaturesPlugin/Test/TestMultiBoolean.py +++ b/src/FeaturesPlugin/Test/TestMultiBoolean.py @@ -90,8 +90,6 @@ for i in xrange(0, N * N): anExtrusionFt = aPart.addFeature("Extrusion") assert (anExtrusionFt.getKind() == "Extrusion") - # selection type FACE=4 - anExtrusionFt.selectionList("base").setSelectionType(4) anExtrusionFt.selectionList("base").append( aSketchResult, aSketchFaces[0]) anExtrusionFt.real("size").setValue(10) @@ -151,8 +149,6 @@ GeomAlgoAPI_SketchBuilder.createFaces( origin, dirX, dirY, norm, aSketchEdges, aSketchFaces) # Create extrusion on them aBox = aPart.addFeature("Extrusion") -# selection type FACE=4 -aBox.selectionList("base").setSelectionType(4) aBox.selectionList("base").append( aSketchResult, aSketchFaces[0]) aBox.real("size").setValue(10) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 53c04b686..b6fe2ea02 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -777,25 +777,33 @@ std::string Model_AttributeSelection::namingName() TopAbs_ShapeEnum translateType (const std::string& theType) { - TCollection_AsciiString aStr(theType.c_str()); - aStr.UpperCase(); - if(aStr.IsEqual("COMP")) - return TopAbs_COMPOUND; - else if(aStr.IsEqual("COMS")) - return TopAbs_COMPSOLID; - else if(aStr.IsEqual("SOLD")) - return TopAbs_SOLID; - else if(aStr.IsEqual("SHEL")) - return TopAbs_SHELL; - else if(aStr.IsEqual("FACE")) - return TopAbs_FACE; - else if(aStr.IsEqual("WIRE")) - return TopAbs_WIRE; - else if(aStr.IsEqual("EDGE")) - return TopAbs_EDGE; - else if(aStr.IsEqual("VERT")) - return TopAbs_VERTEX; - + // map from the textual shape types to OCCT enumeration + static std::map MyShapeTypes; + if (MyShapeTypes.size() == 0) { + MyShapeTypes["face"] = TopAbs_FACE; + MyShapeTypes["faces"] = TopAbs_FACE; + MyShapeTypes["vertex"] = TopAbs_VERTEX; + MyShapeTypes["vertices"] = TopAbs_VERTEX; + MyShapeTypes["wire"] = TopAbs_WIRE; + MyShapeTypes["edge"] = TopAbs_EDGE; + MyShapeTypes["edges"] = TopAbs_EDGE; + MyShapeTypes["shell"] = TopAbs_SHELL; + MyShapeTypes["solid"] = TopAbs_SOLID; + MyShapeTypes["solids"] = TopAbs_SOLID; + MyShapeTypes["FACE"] = TopAbs_FACE; + MyShapeTypes["FACES"] = TopAbs_FACE; + MyShapeTypes["VERTEX"] = TopAbs_VERTEX; + MyShapeTypes["VERTICES"] = TopAbs_VERTEX; + MyShapeTypes["WIRE"] = TopAbs_WIRE; + MyShapeTypes["EDGE"] = TopAbs_EDGE; + MyShapeTypes["EDGES"] = TopAbs_EDGE; + MyShapeTypes["SHELL"] = TopAbs_SHELL; + MyShapeTypes["SOLID"] = TopAbs_SOLID; + MyShapeTypes["SOLIDS"] = TopAbs_SOLID; + } + if (MyShapeTypes.find(theType) != MyShapeTypes.end()) + return MyShapeTypes[theType]; + Events_Error::send("Shape type defined in XML is not implemented!"); return TopAbs_SHAPE; } diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 0643a520b..000ba2b0d 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -42,21 +42,7 @@ void Model_AttributeSelectionList::append(std::string theNamingName) aNewAttr->setObject(owner()); } mySize->Set(aNewTag); - TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)selectionType(); - string aTypeName; - switch(aType) { - case TopAbs_VERTEX: aTypeName = "VERT"; break; - case TopAbs_EDGE: aTypeName = "EDGE"; break; - case TopAbs_WIRE: aTypeName = "WIRE"; break; - case TopAbs_FACE: aTypeName = "FACE"; break; - case TopAbs_SHELL: aTypeName = "SHEL"; break; - case TopAbs_SOLID: aTypeName = "SOLD"; break; - case TopAbs_COMPOUND: aTypeName = "COMP"; break; - case TopAbs_COMPSOLID: aTypeName = "COMS"; break; - default: - return; // invalid case => empty new attribute - }; - aNewAttr->selectSubShape(aTypeName, theNamingName); + aNewAttr->selectSubShape(selectionType(), theNamingName); owner()->data()->sendAttributeUpdated(this); } @@ -65,14 +51,14 @@ int Model_AttributeSelectionList::size() return mySize->Get(); } -int Model_AttributeSelectionList::selectionType() +const std::string Model_AttributeSelectionList::selectionType() const { - return (int) mySelectionType->Get(); + return TCollection_AsciiString(mySelectionType->Get()).ToCString(); } -void Model_AttributeSelectionList::setSelectionType(int theType) +void Model_AttributeSelectionList::setSelectionType(const std::string& theType) { - mySelectionType->Set((double) theType); + mySelectionType->Set(theType.c_str()); } std::shared_ptr @@ -107,8 +93,8 @@ Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; if (!myIsInitialized) { mySize = TDataStd_Integer::Set(theLabel, 0); - mySelectionType = TDataStd_Real::Set(theLabel, 0); + mySelectionType = TDataStd_Comment::Set(theLabel, ""); } else { // recollect mySubs - theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType); + theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType); } } diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index eacc518c6..584c170e9 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -11,7 +11,7 @@ #include "Model_AttributeSelection.h" #include #include -#include +#include #include /**\class Model_AttributeSelectionList @@ -23,7 +23,7 @@ class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList { Handle(TDataStd_Integer) mySize; ///< Contains size of this list - Handle(TDataStd_Real) mySelectionType; ///< Contains current index, TODO: make it integer, not real + Handle(TDataStd_Comment) mySelectionType; ///< Contains current type name (same as selection attribute) public: /// Adds the new reference to the end of the list MODEL_EXPORT virtual void append( @@ -38,11 +38,11 @@ public: /// The type of all elements selection /// \returns the index of the OCCT enumeration of the type of shape - MODEL_EXPORT virtual int selectionType(); + MODEL_EXPORT virtual const std::string selectionType() const; /// Sets the type of all elements selection /// \param theType the index of the OCCT enumeration of the type of shape - MODEL_EXPORT virtual void setSelectionType(int theType); + MODEL_EXPORT virtual void setSelectionType(const std::string& theType); /// Returns the attribute selection by the index (zero based) MODEL_EXPORT virtual std::shared_ptr value(const int theIndex); diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index b8aeabaff..6ded256f5 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -67,8 +67,9 @@ void Model_Data::setName(const std::string& theName) } } -void Model_Data::addAttribute(const std::string& theID, const std::string theAttrType) +AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType) { + AttributePtr aResult; TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1); ModelAPI_Attribute* anAttr = 0; if (theAttrType == ModelAPI_AttributeDocRef::type()) { @@ -103,12 +104,14 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt anAttr = new GeomData_Point2D(anAttrLab); } if (anAttr) { - myAttrs[theID] = std::shared_ptr(anAttr); + aResult = std::shared_ptr(anAttr); + myAttrs[theID] = aResult; anAttr->setObject(myObject); anAttr->setID(theID); } else { Events_Error::send("Can not create unknown type of attribute " + theAttrType); } + return aResult; } // macro for gthe generic returning of the attribute by the ID diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 1787b2a9e..4695446ce 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -134,7 +134,9 @@ class Model_Data : public ModelAPI_Data /// for each attribute of the object /// \param theID identifier of the attribute that can be referenced by this ID later /// \param theAttrType type of the created attribute (received from the type method) - MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType); + /// \returns the just created attribute + MODEL_EXPORT virtual AttributePtr + addAttribute(const std::string& theID, const std::string theAttrType); /// Useful method for "set" methods of the attributes: sends an UPDATE event and /// makes attribute initialized diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index cc8077e32..19e888f15 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -32,11 +32,11 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute /// The type of all elements selection /// \returns the index of the enumeration of the type of shape - virtual int selectionType() = 0; + virtual const std::string selectionType() const = 0; /// Sets the type of all elements selection /// \param theType the index of the enumeration of the type of shape - virtual void setSelectionType(int theType) = 0; + virtual void setSelectionType(const std::string& theType) = 0; /// Returns the attribute selection by the index (zero based) virtual std::shared_ptr value(const int theIndex) = 0; diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 2d6baddb0..f9abb5367 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -13,6 +13,7 @@ #include #include +class ModelAPI_Attribute; class ModelAPI_AttributeDocRef; class ModelAPI_AttributeInteger; class ModelAPI_AttributeDouble; @@ -101,7 +102,9 @@ class MODELAPI_EXPORT ModelAPI_Data /// for each attribute of the object /// \param theID identifier of the attribute that can be referenced by this ID later /// \param theAttrType type of the created attribute (received from the type method) - virtual void addAttribute(const std::string& theID, const std::string theAttrType) = 0; + /// \returns the just created attribute + virtual std::shared_ptr + addAttribute(const std::string& theID, const std::string theAttrType) = 0; /// Useful method for "set" methods of the attributes: sends an UPDATE event and /// makes attribute initialized diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index cef4dbf0d..e816891a6 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -133,7 +133,7 @@ bool ModuleBase_WidgetMultiSelector::storeValueCustom() const // Store shapes type TopAbs_ShapeEnum aCurrentType = ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText()); - aSelectionListAttr->setSelectionType((int) aCurrentType); + aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString()); // Store selection in the attribute foreach (GeomSelection aSelec, mySelection) { aSelectionListAttr->append(aSelec.first, aSelec.second); @@ -158,8 +158,8 @@ bool ModuleBase_WidgetMultiSelector::restoreValue() if (aSelectionListAttr) { mySelection.clear(); // Restore shape type - TopAbs_ShapeEnum aShapeType = (TopAbs_ShapeEnum) aSelectionListAttr->selectionType(); - setCurrentShapeType(aShapeType); + setCurrentShapeType( + ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str())); // Restore selection in the list for (int i = 0; i < aSelectionListAttr->size(); i++) { AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);