]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added 'selectSubShape' for sub-shape selection by name for faces.
authorszy <szy@opencascade.com>
Fri, 26 Dec 2014 15:37:35 +0000 (18:37 +0300)
committerszy <szy@opencascade.com>
Fri, 26 Dec 2014 15:37:35 +0000 (18:37 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelection.h

index f610b3dbefb7161ab8e292fcfac57b0dfd7e6539..6e7e78cd24f3b9e53296be35ab9b499a7e79dcf2 100644 (file)
@@ -620,3 +620,115 @@ std::string Model_AttributeSelection::namingName()//std::shared_ptr<GeomAPI_Shap
   }
   return aName;
 }
+
+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;  
+
+  return TopAbs_SHAPE;
+}
+
+const TopoDS_Shape getShapeFromCompound(const std::string& theSubShapeName, const TopoDS_Shape& theCompound)
+{
+  TopoDS_Shape aSelection;
+  std::string::size_type n = theSubShapeName.rfind('/');                       
+  if (n == std::string::npos) n = 1;
+       std::string aSubString = theSubShapeName.substr(n);
+       n = aSubString.rfind('_');
+       if (n == std::string::npos) return aSelection;
+       aSubString = aSubString.substr(n+1);
+       int indx = atoi(aSubString.c_str());
+       TopoDS_Iterator it(theCompound);                        
+       for (int i = 1;it.More();it.Next(), i++) {
+         if(i == indx) {                         
+           aSelection = it.Value();                      
+           break;
+         }
+         else continue;                                                
+       }
+  return aSelection;   
+}
+
+const TopoDS_Shape findFaceByName(const std::string& theSubShapeName, std::shared_ptr<Model_Document> theDoc)
+{
+  TopoDS_Shape aFace;
+  const TDF_Label& aLabel = theDoc->findNamingName(theSubShapeName);
+  if(aLabel.IsNull()) return aFace;
+  Handle(TNaming_NamedShape) aNS;
+  if(aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
+       const TopoDS_Shape& aShape = aNS->Get();
+       if(!aShape.IsNull()) {
+         if(aShape.ShapeType() == TopAbs_COMPOUND) 
+           aFace = getShapeFromCompound(theSubShapeName, aShape);
+         else 
+               aFace = aShape;   
+       }
+  }
+  return aFace;
+}
+void Model_AttributeSelection::selectSubShape(const std::string& theType, const std::string& theSubShapeName)
+{
+  if(theSubShapeName.empty() || theType.empty()) return;
+  TopAbs_ShapeEnum aType = translateType(theType);
+  ResultPtr aCont = context();
+  if(!aCont.get() || aCont->shape()->isNull()) return;
+  TopoDS_Shape aContext  = aCont->shape()->impl<TopoDS_Shape>();
+  TopAbs_ShapeEnum aContType = aContext.ShapeType();
+  if(aType <= aContType) return; // not applicable
+
+  std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(aCont->document());
+  TopoDS_Shape aSelection;
+  switch (aType) 
+  {
+  case TopAbs_COMPOUND:
+    break;
+  case TopAbs_COMPSOLID:
+    break;
+  case TopAbs_SOLID:
+    break;
+  case TopAbs_SHELL:
+    break;
+  case TopAbs_FACE:
+    {
+         const TopoDS_Shape aSelection = findFaceByName(theSubShapeName, aDoc);
+         if(!aSelection.IsNull()) {// Select it
+               std::shared_ptr<GeomAPI_Shape> aShapeToBeSelected(new GeomAPI_Shape());
+        aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelection));
+               setValue(aCont, aShapeToBeSelected);
+         }
+       }
+    break;
+  case TopAbs_WIRE:
+       break;
+  case TopAbs_EDGE:
+       {
+      TopTools_ListOfShape aList;
+         std::list<std::string> aListofNames;
+         //ParseEdgeName();
+
+       }
+    break;
+  case TopAbs_VERTEX:
+       break;
+  default: //TopAbs_SHAPE
+       return;
+  }
+
+}
\ No newline at end of file
index 74c77344d5daea843647d8d2c63ad4cf0d1f0d7c..4ca2ef3db2230fcd79ebd748144f3f6bce4ddf9e 100644 (file)
@@ -42,6 +42,9 @@ public:
   /// Returns a textual string of the selection
   MODEL_EXPORT virtual std::string namingName();
 
+  /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
+  MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName);
+
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
@@ -50,6 +53,7 @@ protected:
   /// Performs the selection for the body result (TNaming selection)
   virtual void selectBody(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
+
   /// Performs the selection for the construction result (selection by index)
   virtual void selectConstruction(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
index b562410252ee7c2f54b56e52bb9e34c6de5048bf..3778ecdd4d30acc48d75b552e9ebb62df3c67378 100644 (file)
@@ -48,8 +48,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
   virtual std::string namingName() = 0;
 
 
-  /// Selects sub-shape by Name
-  //virtual selectSubShape(const std::string& theSubShapeName, const std::string& theContextShapeName)
+  /// Selects sub-shape by the textual Name
+  virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0;
+
   /// To virtually destroy the fields of successors
   virtual ~ModelAPI_AttributeSelection()
   {