]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Topological names management: add "buildSubShapeName".
authorszy <szy@opencascade.com>
Tue, 23 Dec 2014 15:06:03 +0000 (18:06 +0300)
committerszy <szy@opencascade.com>
Tue, 23 Dec 2014 15:06:03 +0000 (18:06 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelection.h

index f76344f552f6d0e976e26a7910c6dccb6b6c1666..aa3d7c9760acdd0b0c11ff4f2790944655ef0656 100644 (file)
@@ -35,7 +35,9 @@
 #include <Precision.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TDF_ChildIDIterator.hxx>
-
+#include <TDataStd_Name.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopoDS_Iterator.hxx>
 using namespace std;
 /// adeed to the index in the packed map to signalize that the vertex of edge is seleted
 /// (multiplied by the index of the edge)
@@ -65,6 +67,10 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   else if (theContext->groupName() == ModelAPI_ResultConstruction::group())
     selectConstruction(theContext, theSubShape);
 
+  std::string aSelName = buildSubShapeName(theSubShape, theContext);
+  if(!aSelName.empty())
+         TDataStd_Name::Set(selectionLabel(), aSelName.c_str()); //set name
+
   myIsInitialized = true;
   owner()->data()->sendAttributeUpdated(this);
 }
@@ -426,3 +432,56 @@ TDF_Label Model_AttributeSelection::selectionLabel()
 {
   return myRef.myRef->Label().FindChild(1);
 }
+
+std::string Model_AttributeSelection::buildSubShapeName(std::shared_ptr<GeomAPI_Shape> theSubShape, 
+                                                           const ResultPtr& theContext)
+{
+  std::string aName;
+  if(theSubShape->isNull() || theContext->shape()->isNull()) return aName;  
+  TopoDS_Shape aSubShape = theSubShape->impl<TopoDS_Shape>();
+  TopoDS_Shape aContext  = theContext->shape()->impl<TopoDS_Shape>();
+
+  // check if the subShape is already in DF
+  Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aSubShape, selectionLabel());
+  Handle(TDataStd_Name) anAttr;
+  if(!aNS.IsNull()) { // in the document    
+       if(aNS->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) {
+         aName = TCollection_AsciiString(anAttr->Get()).ToCString();
+         if(!aName.empty()) {
+           std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theContext->document());
+           const TDF_Label& aLabel = aDoc->findNamingName(aName);
+               if(!aLabel.IsEqual(aNS->Label())) {
+                       aName.erase(); //something is wrong, to be checked!
+               }
+               const TopoDS_Shape& aShape = aNS->Get();
+               if(aShape.ShapeType() == TopAbs_COMPOUND) {
+                 std::string aFullName = aName + "_";
+                 TopoDS_Iterator it(aShape);
+                       int i(1);
+                       for (;it.More();it.Next(), i++) {
+                         if(it.Value() != aSubShape) continue;
+                         else {
+                               aName = aFullName + TCollection_AsciiString (i).ToCString();
+                               break;
+                         }
+                       }
+               }
+         }     
+       }
+  }
+  if(aName.empty() ) { // not in the document!
+    TopAbs_ShapeEnum aType = aSubShape.ShapeType();
+       switch (aType) {
+         case TopAbs_FACE:
+      // the Face should be in DF. If it is not a case it is an error ==> to be dbugged
+               
+               break;
+         case TopAbs_EDGE:
+                 break;
+         case TopAbs_VERTEX:
+                 break;
+
+       }
+  }
+  return aName;
+}
index bc6933d39a3bdfc092d091db8568a1931def4b54..8cfd02f30a2404f4ed3ca0342072dda96f13bb08 100644 (file)
@@ -39,6 +39,10 @@ public:
   /// \returns false if update is failed
   MODEL_EXPORT virtual bool update();
 
+  /// builds name of the SubShape 
+  MODEL_EXPORT virtual std::string buildSubShapeName(std::shared_ptr<GeomAPI_Shape> theSubShape, 
+                                                        const ResultPtr& theContext);
+
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
index 600a9820448d4dc79ec1079ad1cb12a7ec83cc4a..4e8f2a51e5adb8be71200a7c8d97f57a7b184e5c 100644 (file)
@@ -44,6 +44,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
     return type();
   }
 
+  /// builds name of the SubShape 
+  virtual std::string buildSubShapeName(std::shared_ptr<GeomAPI_Shape> theSubShape, 
+                                           const ResultPtr& theContext) = 0;
   /// To virtually destroy the fields of successors
   virtual ~ModelAPI_AttributeSelection()
   {