]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Sketcher Offset: API
authorjfa <jfa@opencascade.com>
Wed, 24 Jun 2020 14:02:58 +0000 (17:02 +0300)
committerjfa <jfa@opencascade.com>
Wed, 24 Jun 2020 14:02:58 +0000 (17:02 +0300)
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Offset.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_Offset.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/SketchAPI_swig.h
src/SketchPlugin/SketchPlugin_Offset.cpp
src/SketchPlugin/SketchPlugin_Offset.h

index c81d857be876744e1ae073b9f30c09cd77b8b3f7..3b5b813477e1100039fb5ae6081594a249aaba5e 100644 (file)
@@ -35,6 +35,7 @@ SET(PROJECT_HEADERS
   SketchAPI_MacroEllipse.h
   SketchAPI_MacroEllipticArc.h
   SketchAPI_Mirror.h
+  SketchAPI_Offset.h
   SketchAPI_Point.h
   SketchAPI_Projection.h
   SketchAPI_Rectangle.h
@@ -59,6 +60,7 @@ SET(PROJECT_SOURCES
   SketchAPI_MacroEllipse.cpp
   SketchAPI_MacroEllipticArc.cpp
   SketchAPI_Mirror.cpp
+  SketchAPI_Offset.cpp
   SketchAPI_Point.cpp
   SketchAPI_Projection.cpp
   SketchAPI_Rectangle.cpp
index ba30a72da6938d6d677faf9fbecc8a08e9ea12ec..2ee3108cd039212729bb1684e3394d04562b43dd 100644 (file)
@@ -71,6 +71,7 @@
 %shared_ptr(SketchAPI_IntersectionPoint)
 %shared_ptr(SketchAPI_Line)
 %shared_ptr(SketchAPI_Mirror)
+%shared_ptr(SketchAPI_Offset)
 %shared_ptr(SketchAPI_Sketch)
 %shared_ptr(SketchAPI_SketchEntity)
 %shared_ptr(SketchAPI_Point)
 %include "SketchAPI_BSpline.h"
 %include "SketchAPI_Projection.h"
 %include "SketchAPI_Mirror.h"
+%include "SketchAPI_Offset.h"
 %include "SketchAPI_Translation.h"
 %include "SketchAPI_Rectangle.h"
 %include "SketchAPI_Rotation.h"
diff --git a/src/SketchAPI/SketchAPI_Offset.cpp b/src/SketchAPI/SketchAPI_Offset.cpp
new file mode 100644 (file)
index 0000000..6d4f24e
--- /dev/null
@@ -0,0 +1,108 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SketchAPI_Offset.h"
+#include <SketchAPI_SketchEntity.h>
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+//--------------------------------------------------------------------------------------
+SketchAPI_Offset::SketchAPI_Offset (const std::shared_ptr<ModelAPI_Feature> & theFeature)
+  : ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+SketchAPI_Offset::SketchAPI_Offset (const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                                    const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+                                    const ModelHighAPI_Double & theOffsetValue,
+                                    bool theIsReversed,
+                                    bool theIsAuxiliary)
+  : ModelHighAPI_Interface(theFeature)
+{
+  if (initialize()) {
+    fillAttribute(theObjects, edgesList());
+    fillAttribute(theOffsetValue, value());
+    fillAttribute(theIsReversed, reversed());
+    fillAttribute(theIsAuxiliary, auxiliary());
+
+    execute();
+  }
+}
+
+SketchAPI_Offset::~SketchAPI_Offset()
+{
+}
+
+std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Offset::offset() const
+{
+  std::list<ObjectPtr> aList = createdList()->list();
+  std::list<FeaturePtr> anIntermediate;
+  std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+  for (; anIt != aList.end(); ++anIt) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+    anIntermediate.push_back(aFeature);
+  }
+  return SketchAPI_SketchEntity::wrap(anIntermediate);
+}
+
+//--------------------------------------------------------------------------------------
+
+void SketchAPI_Offset::dump (ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aSketchName = theDumper.parentName(aBase);
+
+  AttributeRefListPtr aOffsetObjects = edgesList();
+  AttributeDoublePtr aValue = value();
+  AttributeBooleanPtr aReversed = reversed();
+  AttributeBooleanPtr anAux = auxiliary();
+
+  // Check all attributes are already dumped. If not, store the feature as postponed.
+  if (!theDumper.isDumped(aOffsetObjects)) {
+    theDumper.postpone(aBase);
+    return;
+  }
+
+  theDumper << aBase << " = " << aSketchName << ".addOffset(" << aOffsetObjects << ", "
+            << aValue << ", " << aReversed << ", " << anAux << ")" << std::endl;
+
+  // Dump variables for a list of created features
+  theDumper << "[";
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = offset();
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
+  for (; anIt != aList.end(); ++anIt) {
+    if (anIt != aList.begin())
+      theDumper << ", ";
+    theDumper << (*anIt)->feature();
+  }
+  theDumper << "] = " << theDumper.name(aBase) << ".offset()" << std::endl;
+
+  // Set necessary "auxiliary" flag for created features
+  // (flag is set if it differs to anAux)
+  for (anIt = aList.begin(); anIt != aList.end(); ++anIt) {
+    FeaturePtr aFeature = (*anIt)->feature();
+    bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
+    if (aFeatAux != anAux->value())
+      theDumper << theDumper.name((*anIt)->feature(), false)
+                << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
+  }
+}
diff --git a/src/SketchAPI/SketchAPI_Offset.h b/src/SketchAPI/SketchAPI_Offset.h
new file mode 100644 (file)
index 0000000..98412a8
--- /dev/null
@@ -0,0 +1,90 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SRC_SKETCHAPI_SKETCHAPI_OFFSET_H_
+#define SRC_SKETCHAPI_SKETCHAPI_OFFSET_H_
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI.h"
+#include "SketchAPI_SketchEntity.h"
+
+#include <list>
+
+#include <SketchPlugin_Offset.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+//--------------------------------------------------------------------------------------
+class ModelAPI_Object;
+class ModelHighAPI_RefAttr;
+class ModelHighAPI_Double;
+//--------------------------------------------------------------------------------------
+/**\class SketchAPI_Offset
+ * \ingroup CPPHighAPI
+ * \brief Interface for Offset feature
+ */
+class SketchAPI_Offset : public ModelHighAPI_Interface
+{
+public:
+  /// Constructor without values
+  SKETCHAPI_EXPORT
+  explicit SketchAPI_Offset(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Offset(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                   const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+                   const ModelHighAPI_Double & theOffsetValue,
+                   bool theIsReversed,
+                   bool theIsAuxiliary);
+  /// Destructor
+  SKETCHAPI_EXPORT
+  virtual ~SketchAPI_Offset();
+
+  INTERFACE_5(SketchPlugin_Offset::ID(),
+
+              edgesList, SketchPlugin_Offset::EDGES_ID(),
+              ModelAPI_AttributeRefList, /** Offset edges list */,
+
+              value, SketchPlugin_Offset::VALUE_ID(),
+              ModelAPI_AttributeDouble, /** Value */,
+
+              reversed, SketchPlugin_Offset::REVERSED_ID(),
+              ModelAPI_AttributeBoolean, /** Negative value */,
+
+              auxiliary, SketchPlugin_Offset::AUXILIARY_ID(),
+              ModelAPI_AttributeBoolean, /** Auxiliary */,
+
+              createdList, SketchPlugin_Offset::CREATED_ID(),
+              ModelAPI_AttributeRefList, /** Created edges list */
+              )
+
+  /// List of created objects
+  SKETCHAPI_EXPORT
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> > offset() const;
+
+  /// Dump wrapped feature
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+//! Pointer on Offset object
+typedef std::shared_ptr<SketchAPI_Offset> OffsetPtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SKETCHAPI_SKETCHAPI_OFFSET_H_ */
index c713dfd9708cac420ed2780f3ab3c19e70223de9..2046d51034ac09bb02ea8ecde234ffc196d35454 100644 (file)
@@ -43,6 +43,7 @@
 #include <SketchPlugin_ConstraintVertical.h>
 #include <SketchPlugin_MacroBSpline.h>
 #include <SketchPlugin_SketchCopy.h>
+#include <SketchPlugin_Offset.h>
 #include <SketcherPrs_Tools.h>
 //--------------------------------------------------------------------------------------
 #include <ModelAPI_Events.h>
@@ -67,6 +68,7 @@
 #include "SketchAPI_MacroEllipse.h"
 #include "SketchAPI_MacroEllipticArc.h"
 #include "SketchAPI_Mirror.h"
+#include "SketchAPI_Offset.h"
 #include "SketchAPI_Point.h"
 #include "SketchAPI_Projection.h"
 #include "SketchAPI_Rectangle.h"
@@ -889,6 +891,18 @@ std::shared_ptr<SketchAPI_Mirror> SketchAPI_Sketch::addMirror(
   return MirrorPtr(new SketchAPI_Mirror(aFeature, theMirrorLine, theObjects));
 }
 
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Offset> SketchAPI_Sketch::addOffset(
+    const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+    const ModelHighAPI_Double & theValue,
+    const bool theReversed,
+    const bool theAuxiliary)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchPlugin_Offset::ID());
+  return OffsetPtr(new SketchAPI_Offset(aFeature, theObjects, theValue, theReversed, theAuxiliary));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Translation> SketchAPI_Sketch::addTranslation(
     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
index 30674f4fb64069973af9da35bf32bbead85197db..6174ca23fd90dee5e5ee046edeb03891e4633698 100644 (file)
@@ -50,6 +50,7 @@ class SketchAPI_BSpline;
 class SketchAPI_IntersectionPoint;
 class SketchAPI_Line;
 class SketchAPI_Mirror;
+class SketchAPI_Offset;
 class SketchAPI_Point;
 class SketchAPI_Projection;
 class SketchAPI_Rectangle;
@@ -370,6 +371,14 @@ public:
       const ModelHighAPI_RefAttr & theMirrorLine,
       const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects);
 
+  /// Add offset
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Offset> addOffset(
+      const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
+      const ModelHighAPI_Double & theValue,
+      const bool theReversed,
+      const bool theAuxiliary);
+
   /// Add translation
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Translation> addTranslation(
index 28370b70ce25ebc7c50275432d0d4c4d194e2abb..d166f4e5175ecd4cde4ddd68589dd8662c1ac66a 100644 (file)
@@ -37,6 +37,7 @@
   #include "SketchAPI_IntersectionPoint.h"
   #include "SketchAPI_Line.h"
   #include "SketchAPI_Mirror.h"
+  #include "SketchAPI_Offset.h"
   #include "SketchAPI_Sketch.h"
   #include "SketchAPI_SketchEntity.h"
   #include "SketchAPI_Point.h"
index 6ff21485855b0813970661562843bceae48f862f..a9ccb1c977f4640b6c9b4b518a2e76e7c3584b0a 100644 (file)
 #include <ModelAPI_AttributeDoubleArray.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Events.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_Validator.h>
 
 #include <GeomAlgoAPI_Offset.h>
 #include <GeomAlgoAPI_ShapeTools.h>
@@ -66,12 +68,14 @@ void SketchPlugin_Offset::initDerivedClassAttributes()
   data()->addAttribute(EDGES_ID(), ModelAPI_AttributeRefList::typeId());
   data()->addAttribute(VALUE_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId());
+  data()->addAttribute(CREATED_ID(), ModelAPI_AttributeRefList::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATED_ID());
 }
 
 void SketchPlugin_Offset::execute()
 {
-  ModelAPI_Tools::removeFeaturesAndReferences(myCreatedFeatures);
-  myCreatedFeatures.clear();
+  removeCreated(); // remove created objects
 
   SketchPlugin_Sketch* aSketch = sketch();
   if (!aSketch) return;
@@ -105,6 +109,12 @@ void SketchPlugin_Offset::execute()
     }
   }
 
+  // Wait all objects being created, then send update events
+  static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+  bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+  if (isUpdateFlushed)
+    Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+
   // 5. Gather wires and make offset for each wire
   for (anEdgesIt = anEdgesList.begin(); anEdgesIt != anEdgesList.end(); anEdgesIt++) {
     FeaturePtr aFeature = ModelAPI_Feature::feature(*anEdgesIt);
@@ -146,10 +156,14 @@ void SketchPlugin_Offset::execute()
 
       // 5.e. Store offset results.
       //      Create sketch feature for each edge of anOffsetShape, and also store
-      //      created features in myCreatedFeatures to remove them on next execute()
+      //      created features in CREATED_ID() to remove them on next execute()
       addToSketch(anOffsetShape);
     }
   }
+
+  // send events to update the sub-features by the solver
+  if (isUpdateFlushed)
+    Events_Loop::loop()->setFlushed(anUpdateEvent, true);
 }
 
 bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge,
@@ -255,7 +269,10 @@ bool SketchPlugin_Offset::findWireOneWay (const FeaturePtr& theFirstEdge,
 
 void SketchPlugin_Offset::addToSketch(const std::shared_ptr<GeomAPI_Shape>& anOffsetShape)
 {
-  //GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer
+  AttributeRefListPtr aRefListOfCreated =
+    std::dynamic_pointer_cast<ModelAPI_AttributeRefList>
+    (data()->attribute(SketchPlugin_Offset::CREATED_ID()));
+
   ListOfShape aResEdges = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(anOffsetShape);
   std::list<GeomShapePtr>::const_iterator aResEdgesIt = aResEdges.begin();
   for (; aResEdgesIt != aResEdges.end(); aResEdgesIt++) {
@@ -352,7 +369,7 @@ void SketchPlugin_Offset::addToSketch(const std::shared_ptr<GeomAPI_Shape>& anOf
       }
 
       if (aResFeature.get()) {
-        myCreatedFeatures.insert(aResFeature);
+        aRefListOfCreated->append(aResFeature);
 
         aResFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue
           (boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value());
@@ -423,8 +440,26 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult,
 
 void SketchPlugin_Offset::attributeChanged(const std::string& theID)
 {
-  ModelAPI_Tools::removeFeaturesAndReferences(myCreatedFeatures);
-  myCreatedFeatures.clear();
+  removeCreated();
+}
+
+void SketchPlugin_Offset::removeCreated()
+{
+  if (!sketch()) return;
+
+  // Remove all created objects
+  AttributeRefListPtr aRefListOfCreated =
+    std::dynamic_pointer_cast<ModelAPI_AttributeRefList>
+    (data()->attribute(SketchPlugin_Offset::CREATED_ID()));
+  std::list<ObjectPtr> aList = aRefListOfCreated->list();
+  std::set<FeaturePtr> aSet;
+  std::list<ObjectPtr>::iterator anIter = aList.begin();
+  for (; anIter != aList.end(); anIter++) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(*anIter);
+    aSet.insert(aFeature);
+  }
+  ModelAPI_Tools::removeFeaturesAndReferences(aSet);
+  aRefListOfCreated->clear();
 }
 
 bool SketchPlugin_Offset::customAction(const std::string& theActionId)
index f8a86036df6f80d8356ef4d3f870c95d20b4dc90..482a752457f0774aa98a0f844f7e0ba261247103 100644 (file)
@@ -70,6 +70,13 @@ public:
     return ID;
   }
 
+  /// attribute to store the created objects
+  inline static const std::string& CREATED_ID()
+  {
+    static const std::string ID("created");
+    return ID;
+  }
+
   /// name for add wire action
   inline static const std::string& ADD_WIRE_ACTION_ID()
   {
@@ -112,9 +119,12 @@ private:
   bool findWires();
 
   // Create sketch feature for each edge of theOffsetResult,
-  // and store it in myCreatedFeatures to remove on next execute()
+  // and store it in CREATED_ID()
   void addToSketch (const std::shared_ptr<GeomAPI_Shape>& theOffsetResult);
 
+  // Remove created features
+  void removeCreated ();
+
   // Create BSpline or BSplinePeriodic sketch feature from theEdge
   void mkBSpline (FeaturePtr& theResult, const GeomEdgePtr& theEdge);
 
@@ -133,9 +143,6 @@ private:
                        std::set<FeaturePtr>& theEdgesSet,
                        std::list<FeaturePtr>& theChain,
                        const bool isPrepend = false);
-
-  // tmp
-  std::set<FeaturePtr> myCreatedFeatures;
 };
 
 #endif