]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authornds <natalia.donis@opencascade.com>
Wed, 18 Mar 2015 08:10:00 +0000 (11:10 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 18 Mar 2015 08:10:00 +0000 (11:10 +0300)
13 files changed:
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/Test/TestBoolean.py
src/FeaturesPlugin/Test/TestExtrusion.py
src/FeaturesPlugin/Test/TestGroup.py
src/FeaturesPlugin/Test/TestMultiBoolean.py
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModelAPI/ModelAPI_Data.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp

index ad23adbcb49f5a167edc8744d1a0b97967f2b188..c84c007022746d820ed0ec06947376a4902cb232 100644 (file)
@@ -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<ModelAPI_AttributeSelectionList>(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());
 }
index 1e6aa1b88bdc400c489ce962995d9f94249aac9c..19158fa536e14bdb8302e929e0487d2f91c964d2 100644 (file)
@@ -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)
index 18595e23bd916b7e492cd73e725b6060ac53955c..f24ee3ce6d873b53e9387c34d1e2320083378a48 100644 (file)
@@ -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)
index 5a9ef243ad1d9f7d76134dd1df835f6f586cb0f0..9692c2cddf3845eb1eb249ec4fc891a841e56c84 100644 (file)
@@ -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()
 #=========================================================================
index 6d26957ea9819d9be832fb041261370ffc37cf36..594c3af72a88068cb7c417781e5a794c26a0fdfd 100644 (file)
@@ -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)
index 53c04b6863ad4cb7fd7eb1dea4ce00907a292e21..b6fe2ea028578e269b300a87f7eb16a00a6f94f5 100644 (file)
@@ -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<std::string, TopAbs_ShapeEnum> 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;
 }
 
index 0643a520bb91a23e620d37c64fefe8413ba3da90..000ba2b0d5565b4a9e11c06097c124e26a7f6529 100644 (file)
@@ -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<ModelAPI_AttributeSelection> 
@@ -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);
   }
 }
index eacc518c6bc8ecbcc0f8bf11b5bd1902ffeb4614..584c170e9c7cb10d5c0b255ba34b691a511968b0 100644 (file)
@@ -11,7 +11,7 @@
 #include "Model_AttributeSelection.h"
 #include <ModelAPI_AttributeSelectionList.h>
 #include <TDataStd_Integer.hxx>
-#include <TDataStd_Real.hxx>
+#include <TDataStd_Comment.hxx>
 #include <vector>
 
 /**\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<ModelAPI_AttributeSelection> value(const int theIndex);
index b8aeabaffbba9e19dd2c04e33422da9bb9c59cea..6ded256f5cf138d69c886d63252e122c213e765c 100644 (file)
@@ -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<ModelAPI_Attribute>(anAttr);
+    aResult = std::shared_ptr<ModelAPI_Attribute>(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
index 1787b2a9e0c2aa9fe9f5a3da79a1f9c7c7c690de..4695446ce9b29eadd7e256b30c837d3f462338b3 100644 (file)
@@ -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
index cc8077e325bfa221c9c0d58aefa784fd53a8c236..19e888f15f8b9e86016b7aa95830275c2c0da495 100644 (file)
@@ -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<ModelAPI_AttributeSelection> value(const int theIndex) = 0;
index 2d6baddb0d7c5b4f7bf59ed71a5647e22e6f5a40..f9abb5367e33759dffbd10b0d77c896459339f91 100644 (file)
@@ -13,6 +13,7 @@
 #include <set>
 #include <memory>
 
+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<ModelAPI_Attribute>
+    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
index cef4dbf0de4876394986ff80beb45be04221bd62..e816891a6585968c16310391fa9e48fa891d3d3b 100644 (file)
@@ -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);