]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 17 Mar 2015 15:16:35 +0000 (18:16 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 17 Mar 2015 15:16:35 +0000 (18:16 +0300)
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.h
src/FeaturesPlugin/Test/TestBoolean.py
src/FeaturesPlugin/Test/TestExtrusion.py
src/FeaturesPlugin/Test/TestGroup.py
src/FeaturesPlugin/Test/TestMultiBoolean.py
src/FeaturesPlugin/extrusion_widget.xml
src/Model/Model_Document.cpp
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h

index d3473fa850734c1f68185faee75bfb61447ed88f..ad23adbcb49f5a167edc8744d1a0b97967f2b188 100644 (file)
@@ -35,59 +35,55 @@ void FeaturesPlugin_Extrusion::initAttributes()
 
 void FeaturesPlugin_Extrusion::execute()
 {
-  std::shared_ptr<ModelAPI_AttributeSelectionList> aFaceRefs = std::dynamic_pointer_cast<
-    ModelAPI_AttributeSelectionList>(data()->attribute(FeaturesPlugin_Extrusion::LIST_ID()));
-  if (aFaceRefs.get() == NULL || aFaceRefs->size() == 0) {
-    clearResult();
-    return;
-  }
-  std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(0);
-  if (!aFaceRef)
-    return;
-
-  std::shared_ptr<GeomAPI_Shape> aFace = 
-    std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
-  if (!aFace)
-    return;
-
-  std::shared_ptr<GeomAPI_Shape> aContext;
-  ResultPtr aContextRes = aFaceRef->context();
-  if (aContextRes && aContextRes->groupName() == ModelAPI_ResultConstruction::group()) {
-    aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
-  }
-  if (!aContext) {
-    static const std::string aContextError = "The selection context is bad";
-    setError(aContextError);
-    return;
-  }
+  AttributeSelectionListPtr aFaceRefs = selectionList(FeaturesPlugin_Extrusion::LIST_ID());
+
+  // for each selected face generate a result
+  int anIndex = 0;
+  for(; anIndex < aFaceRefs->size(); anIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(anIndex);
+    if (!aFaceRef.get())
+      continue;
+    std::shared_ptr<GeomAPI_Shape> aFace = aFaceRef->value();
+    if (!aFace.get())
+      continue;
+    ResultPtr aContextRes = aFaceRef->context();
+    std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
+    if (!aContext.get()) {
+      static const std::string aContextError = "The selection context is bad";
+      setError(aContextError);
+      break;
+    }
 
-  double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
-  if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
-    aSize = -aSize;
+    double aSize = real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
+    if (boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
+      aSize = -aSize;
 
-  std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
-  GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
-  if(!aFeature.isDone()) {
-    static const std::string aFeatureError = "Extrusion algorithm failed";  
-    setError(aFeatureError);
-    return;
-  }
+    ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
+    GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
+    if(!aFeature.isDone()) {
+      static const std::string aFeatureError = "Extrusion algorithm failed";  
+      setError(aFeatureError);
+      break;
+    }
 
-  // Check if shape is valid
-  if (aFeature.shape()->isNull()) {
-    static const std::string aShapeError = "Resulting shape is Null";     
-    setError(aShapeError);
-    return;
+    // Check if shape is valid
+    if (aFeature.shape()->isNull()) {
+      static const std::string aShapeError = "Resulting shape is Null";     
+      setError(aShapeError);
+      break;
+    }
+    if(!aFeature.isValid()) {
+      std::string aFeatureError = "Warning: resulting shape is not valid";  
+      setError(aFeatureError);
+      break;
+    }  
+    //LoadNamingDS
+    LoadNamingDS(aFeature, aResultBody, aFace, aContext);
+
+    setResult(aResultBody, anIndex);
   }
-  if(!aFeature.isValid()) {
-    std::string aFeatureError = "Warning: resulting shape is not valid";  
-    setError(aFeatureError);
-    return;
-  }  
-  //LoadNamingDS
-  LoadNamingDS(aFeature, aResultBody, aFace, aContext);
-
-  setResult(aResultBody);
+  // remove the rest results if there were produced in the previous pass
+  removeResults(anIndex);
 }
 
 //============================================================================
index 87f33180d46f1b46c11bcc91ef32654818610523..2150ce72023c8a72023a77e4775e6b52b0387122 100644 (file)
@@ -30,30 +30,24 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature
     static const std::string MY_EXTRUSION_ID("Extrusion");
     return MY_EXTRUSION_ID;
   }
-  /// attribute name of referenced face
-  inline static const std::string& FACE_ID()
-  {
-    static const std::string MY_FACE_ID("extrusion_face");
-    return MY_FACE_ID;
-  }
   /// attribute name of references sketch entities list, it should contain a sketch result or
   /// a pair a sketch result to sketch face
   inline static const std::string& LIST_ID()
   {
-    static const std::string MY_GROUP_LIST_ID("group_list");
+    static const std::string MY_GROUP_LIST_ID("base");
     return MY_GROUP_LIST_ID;
   }
 
   /// attribute name of extrusion size
   inline static const std::string& SIZE_ID()
   {
-    static const std::string MY_SIZE_ID("extrusion_size");
+    static const std::string MY_SIZE_ID("size");
     return MY_SIZE_ID;
   }
   /// attribute name of reverse direction
   inline static const std::string& REVERSE_ID()
   {
-    static const std::string MY_REVERSE_ID("extrusion_reverse");
+    static const std::string MY_REVERSE_ID("reverse");
     return MY_REVERSE_ID;
   }
 
index 94aa22e8e5158a83d93ef1484d27b742dd054908..1e6aa1b88bdc400c489ce962995d9f94249aac9c 100644 (file)
@@ -95,10 +95,12 @@ for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
         origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
     # Create extrusion on them
     anExtrusionFt = aPart.addFeature("Extrusion")
-    anExtrusionFt.selection("extrusion_face").setValue(
+    # selection type FACE=4
+    anExtrusionFt.selectionList("base").setSelectionType(4)
+    anExtrusionFt.selectionList("base").append(
         aSketchResult, aSketchFaces[0])
-    anExtrusionFt.real("extrusion_size").setValue(50)
-    anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+    anExtrusionFt.real("size").setValue(50)
+    anExtrusionFt.boolean("reverse").setValue(False)
     anExtrusionFt.execute()
     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
 aSession.finishOperation()
index 2d6cc6a5e8f76db48900825116c0bae6bce69605..18595e23bd916b7e492cd73e725b6060ac53955c 100644 (file)
@@ -72,14 +72,16 @@ assert (aSketchFaces[0] is not None)
 aSession.startOperation()
 anExtrusionFt = aPart.addFeature("Extrusion")
 assert (anExtrusionFt.getKind() == "Extrusion")
-anExtrusionFt.selection("extrusion_face").setValue(
+# selection type FACE=4
+anExtrusionFt.selectionList("base").setSelectionType(4)
+anExtrusionFt.selectionList("base").append(
     aSketchResult, aSketchFaces[0])
-anExtrusionFt.real("extrusion_size").setValue(50)
-anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+anExtrusionFt.real("size").setValue(50)
+anExtrusionFt.boolean("reverse").setValue(False)
 anExtrusionFt.execute()
 aSession.finishOperation()
-assert (anExtrusionFt.real("extrusion_size").value() == 50.0)
-assert (anExtrusionFt.boolean("extrusion_reverse").value() == False)
+assert (anExtrusionFt.real("size").value() == 50.0)
+assert (anExtrusionFt.boolean("reverse").value() == False)
 
 # Check extrusion results
 assert (len(anExtrusionFt.results()) > 0)
index bb446e26ccd314ae14e997f5b2aaef6416b63a87..5a9ef243ad1d9f7d76134dd1df835f6f586cb0f0 100644 (file)
@@ -22,8 +22,8 @@ aSession = ModelAPI_Session.get()
 # Create a part for extrusions & boolean
 aSession.startOperation()
 aPartFeature = aSession.moduleDocument().addFeature("Part")
-aPart = aSession.activeDocument()
 aSession.finishOperation()
+aPart = aSession.activeDocument()
 #=========================================================================
 # Create a sketch with triangle and extrude it
 #=========================================================================
@@ -66,10 +66,12 @@ GeomAlgoAPI_SketchBuilder.createFaces(
     origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
 # Create extrusion on them
 anExtrusionFt = aPart.addFeature("Extrusion")
-anExtrusionFt.selection("extrusion_face").setValue(
+# selection type FACE=4
+anExtrusionFt.selectionList("base").setSelectionType(4)
+anExtrusionFt.selectionList("base").append(
     aSketchResult, aSketchFaces[0])
-anExtrusionFt.real("extrusion_size").setValue(50)
-anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+anExtrusionFt.real("size").setValue(50)
+anExtrusionFt.boolean("reverse").setValue(False)
 anExtrusionFt.execute()
 aSession.finishOperation()
 anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
@@ -88,8 +90,8 @@ aSession.finishOperation()
 #=========================================================================
 # Check results
 #=========================================================================
-aGroupResult = aGroupFeature.firstResult()
-assert(aGroupResult)
+#aGroupResult = aGroupFeature.firstResult()
+#assert(aGroupResult)
 #=========================================================================
 # End of test
 #=========================================================================
index 0b7a6390365abe9f44bb3258f8c141fae84dcd66..6d26957ea9819d9be832fb041261370ffc37cf36 100644 (file)
@@ -4,9 +4,9 @@
       
       class FeaturesPlugin_Extrusion : public ModelAPI_Feature
         static const std::string MY_EXTRUSION_ID("Extrusion");
-        static const std::string MY_FACE_ID("extrusion_face");
-        static const std::string MY_SIZE_ID("extrusion_size");
-        static const std::string MY_REVERSE_ID("extrusion_reverse");
+        static const std::string MY_FACE_ID("base");
+        static const std::string MY_SIZE_ID("size");
+        static const std::string MY_REVERSE_ID("reverse");
           
         data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
         data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
@@ -89,10 +89,13 @@ for i in xrange(0, N * N):
 
   anExtrusionFt = aPart.addFeature("Extrusion")
   assert (anExtrusionFt.getKind() == "Extrusion")
-  anExtrusionFt.selection("extrusion_face").setValue(
+
+  # selection type FACE=4
+  anExtrusionFt.selectionList("base").setSelectionType(4)
+  anExtrusionFt.selectionList("base").append(
       aSketchResult, aSketchFaces[0])
-  anExtrusionFt.real("extrusion_size").setValue(10)
-  anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+  anExtrusionFt.real("size").setValue(10)
+  anExtrusionFt.boolean("reverse").setValue(False)
   anExtrusions.append(anExtrusionFt)
 
 aSession.finishOperation()
@@ -148,11 +151,12 @@ GeomAlgoAPI_SketchBuilder.createFaces(
     origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
 # Create extrusion on them
 aBox = aPart.addFeature("Extrusion")
-aBox.selection("extrusion_face").setValue(
+# selection type FACE=4
+aBox.selectionList("base").setSelectionType(4)
+aBox.selectionList("base").append(
     aSketchResult, aSketchFaces[0])
-aBox.real("extrusion_size").setValue(10)
-aBox.boolean("extrusion_reverse").setValue(False)
-
+aBox.real("size").setValue(10)
+aBox.boolean("reverse").setValue(False)
 aSession.finishOperation()
 
 
index 5b7e9cefe8ac92bb7e2130f77cea100bbc325632..d723657a950c0f7345dd84de26c6680d227f72f9 100644 (file)
@@ -1,7 +1,7 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <multi_selector id="group_list"
+  <multi_selector id="base"
     label="Select a sketch face"
     icon=":icons/sketch.png"
     tooltip="Select a sketch face"
@@ -9,7 +9,7 @@
     <selection_filter id="SketchEntityFilter"/>
   </multi_selector>
   <doublevalue
-    id="extrusion_size"
+    id="size"
     label="Size"
     min="0"
     step="1.0"
@@ -18,5 +18,5 @@
     tooltip="Height">
     <validator id="GeomValidators_Positive"/>
   </doublevalue>
-  <boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
+  <boolvalue id="reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
 </source>
index 1846045379e64f5aab250cc435c741240d53b705..53683dc4dc8fd2f0294a262580f1e6b0ed433a05 100644 (file)
@@ -75,7 +75,8 @@ static TCollection_ExtendedString DocFileName(const char* theFileName, const std
 {
   TCollection_ExtendedString aPath((const Standard_CString) theFileName);
   // remove end-separators
-  while(aPath.Length() && (aPath.Value(aPath.Length()) == '\\' || aPath.Value(aPath.Length()) == '/'))
+  while(aPath.Length() && 
+        (aPath.Value(aPath.Length()) == '\\' || aPath.Value(aPath.Length()) == '/'))
     aPath.Remove(aPath.Length());
   aPath += _separator_;
   aPath += theID.c_str();
@@ -583,8 +584,8 @@ FeaturePtr Model_Document::addFeature(std::string theID)
 /// Appenad to the array of references a new referenced label.
 /// If theIndex is not -1, removes element at this index, not theReferenced.
 /// \returns the index of removed element
-static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, const int theIndex =
-                                  -1)
+static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, 
+  const int theIndex = -1)
 {
   int aResult = -1;  // no returned
   Handle(TDataStd_ReferenceArray) aRefs;
@@ -931,7 +932,7 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t
   static Events_ID aToHideEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   aLoop->activateFlushes(false);
 
-  // update all objects by checking are they of labels or not
+  // update all objects by checking are they on labels or not
   std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
   TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
   for (; aLabIter.More(); aLabIter.Next()) {
@@ -1052,7 +1053,8 @@ void Model_Document::synchronizeBackRefs()
     if (aFData) {
       std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
       aFData->referencesToObjects(aRefs);
-      std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefsIter = aRefs.begin();
+      std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator 
+        aRefsIter = aRefs.begin();
       for(; aRefsIter != aRefs.end(); aRefsIter++) {
         std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
         for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
@@ -1099,7 +1101,11 @@ void Model_Document::storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
   theResult->setDoc(aThis);
   initData(theResult, resultLabel(theFeatureData, theResultIndex), TAG_FEATURE_ARGUMENTS);
   if (theResult->data()->name().empty()) {  // if was not initialized, generate event and set a name
-    theResult->data()->setName(theFeatureData->name());
+    std::stringstream aNewName;
+    aNewName<<theFeatureData->name();
+    if (theResultIndex > 0) // if there are several results, add unique prefix starting from second
+      aNewName<<"_"<<theResultIndex + 1;
+    theResult->data()->setName(aNewName.str());
   }
 }
 
index 1a2e641a2981aa18d740c5963c742d56ce8f9418..e158d48a0853f3b6f9603d39fbbd4469515d8fe3 100644 (file)
@@ -89,6 +89,28 @@ void ModelAPI_Feature::removeResult(const std::shared_ptr<ModelAPI_Result>& theR
   }
 }
 
+void ModelAPI_Feature::removeResults(const int theSinceIndex)
+{
+  if (theSinceIndex == 0) {
+    eraseResults();
+    return;
+  }
+
+  std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
+  for(int anIndex = 0; anIndex < theSinceIndex; anIndex++)
+    aResIter++;
+  std::list<std::shared_ptr<ModelAPI_Result> >::iterator aNextIter = aResIter;
+  for(; aNextIter != myResults.end(); aNextIter++) {
+    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+    static Events_Loop* aLoop = Events_Loop::loop();
+    static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+    static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+    ModelAPI_EventCreator::get()->sendDeleted(document(), (*aNextIter)->groupName());
+    aECreator->sendUpdated(*aNextIter, EVENT_DISP);
+  }
+  myResults.erase(aResIter, myResults.end());
+}
+
 void ModelAPI_Feature::eraseResults()
 {
   if (!myResults.empty()) {
index c338e151fd76fe95ed6e1a83a61692fe65ae8987..5572bc08d4147cf49467f2fdc5563ed1ba473ab1 100644 (file)
@@ -75,6 +75,8 @@ class ModelAPI_Feature : public ModelAPI_Object
                                  const int theIndex);
   /// removes the result from the feature
   MODELAPI_EXPORT void removeResult(const std::shared_ptr<ModelAPI_Result>& theResult);
+  /// removes all results starting from the gived index (zero-based)
+  MODELAPI_EXPORT void removeResults(const int theSinceIndex);
   /// removes all results from the feature
   MODELAPI_EXPORT void eraseResults();
   /// removes all fields from this feature: results, data, etc