]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task #3231: Sketcher Offset of a curve
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Mon, 25 May 2020 12:05:31 +0000 (15:05 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 2 Jun 2020 08:05:18 +0000 (11:05 +0300)
Implement the feature for the offset operation.

src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Offset.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Offset.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/plugin-Sketch.xml

index f9ada5439d69d4d5e56e35887d7ba77f11fb4d67..91056a0ed7a4b8dc107febb95c9308fd5ca86f7d 100644 (file)
@@ -63,6 +63,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_MacroEllipticArc.h
     SketchPlugin_MultiRotation.h
     SketchPlugin_MultiTranslation.h
+    SketchPlugin_Offset.h
     SketchPlugin_Plugin.h
     SketchPlugin_Point.h
     SketchPlugin_Projection.h
@@ -116,6 +117,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_MacroEllipticArc.cpp
     SketchPlugin_MultiRotation.cpp
     SketchPlugin_MultiTranslation.cpp
+    SketchPlugin_Offset.cpp
     SketchPlugin_Plugin.cpp
     SketchPlugin_Point.cpp
     SketchPlugin_Projection.cpp
diff --git a/src/SketchPlugin/SketchPlugin_Offset.cpp b/src/SketchPlugin/SketchPlugin_Offset.cpp
new file mode 100644 (file)
index 0000000..269c259
--- /dev/null
@@ -0,0 +1,65 @@
+// Copyright (C) 2020  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 <SketchPlugin_Offset.h>
+
+#include <Events_InfoMessage.h>
+
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefList.h>
+
+
+SketchPlugin_Offset::SketchPlugin_Offset()
+  : SketchPlugin_SketchEntity()
+{
+}
+
+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());
+}
+
+void SketchPlugin_Offset::execute()
+{
+}
+
+void SketchPlugin_Offset::attributeChanged(const std::string& theID)
+{
+}
+
+bool SketchPlugin_Offset::customAction(const std::string& theActionId)
+{
+  bool isOk = false;
+  if (theActionId == ADD_WIRE_ACTION_ID()) {
+    isOk = findWires();
+  }
+  else {
+    std::string aMsg = "Error: Feature \"%1\" does not support action \"%2\".";
+    Events_InfoMessage("SketchPlugin_Offset", aMsg).arg(getKind()).arg(theActionId).send();
+  }
+  return isOk;
+}
+
+bool SketchPlugin_Offset::findWires()
+{
+  return false;
+}
diff --git a/src/SketchPlugin/SketchPlugin_Offset.h b/src/SketchPlugin/SketchPlugin_Offset.h
new file mode 100644 (file)
index 0000000..19fff78
--- /dev/null
@@ -0,0 +1,106 @@
+// Copyright (C) 2020  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 SketchPlugin_Offset_H_
+#define SketchPlugin_Offset_H_
+
+#include <SketchPlugin.h>
+#include <SketchPlugin_SketchEntity.h>
+
+/**\class SketchPlugin_Offset
+ * \ingroup Plugins
+ * \brief Builds offset curves in the sketch.
+ */
+class SketchPlugin_Offset : public SketchPlugin_SketchEntity
+{
+public:
+  /// Offset macro feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string ID("SketchOffset");
+    return ID;
+  }
+
+  /// Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = SketchPlugin_Offset::ID();
+    return MY_KIND;
+  }
+
+  /// list of offset edges
+  inline static const std::string& EDGES_ID()
+  {
+    static const std::string ID("segments");
+    return ID;
+  }
+
+  /// attribute to store the offset value
+  inline static const std::string& VALUE_ID()
+  {
+    static const std::string ID("offset_value");
+    return ID;
+  }
+
+  /// attribute to store the reversed offset direction
+  inline static const std::string& REVERSED_ID()
+  {
+    static const std::string ID("reversed");
+    return ID;
+  }
+
+  /// name for add wire action
+  inline static const std::string& ADD_WIRE_ACTION_ID()
+  {
+    static const std::string ID("add_wire");
+    return ID;
+  }
+
+  /// Called on change of any argument-attribute of this object
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+  /// Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// Reimplemented from ModelAPI_Feature::isMacro().
+  /// \returns true
+  SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
+  SKETCHPLUGIN_EXPORT virtual bool isPreviesNeeded() const { return false; }
+
+  /// Find edges connected by coincident boundary constraint and composing a wire with
+  /// the already selected segments. It means that not more than 2 edges can be connected
+  /// with the coincident point.
+  /// \param[in] theActionId action key id (in following form: Action#Index)
+  /// \return \c false in case the action not performed.
+  SKETCHPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId);
+
+  /// Use plugin manager for features creatio
+  SketchPlugin_Offset();
+
+protected:
+  /// \brief Initializes attributes of derived class.
+  virtual void initDerivedClassAttributes();
+
+private:
+  /// Find all wires connected with the selected edges
+  bool findWires();
+};
+
+#endif
index 3d11107a7ccd24129f7f68bb61e04f65031208e1..3be8ffc56bdfc42eeaa8ed77142cfabdbed4923b 100644 (file)
@@ -51,6 +51,7 @@
 #include <SketchPlugin_MacroCircle.h>
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
+#include <SketchPlugin_Offset.h>
 #include <SketchPlugin_Trim.h>
 #include <SketchPlugin_Split.h>
 #include <SketchPlugin_Validators.h>
@@ -279,6 +280,8 @@ FeaturePtr SketchPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new SketchPlugin_SketchDrawer);
   } else if (theFeatureID == SketchPlugin_SketchCopy::ID()) {
     return FeaturePtr(new SketchPlugin_SketchCopy);
+  } else if (theFeatureID == SketchPlugin_Offset::ID()) {
+    return FeaturePtr(new SketchPlugin_Offset);
   }
   // feature of such kind is not found
   return FeaturePtr();
@@ -356,6 +359,7 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       aMsg->setState(SketchPlugin_MacroEllipticArc::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintDistanceHorizontal::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintDistanceVertical::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_Offset::ID(), aHasSketchPlane);
       // SketchRectangle is a python feature, so its ID is passed just as a string
       aMsg->setState("SketchRectangle", aHasSketchPlane);
     }
index 8d111edbbc9af14d56a744e9149495feaaaf52e6..e7cb8355378e8973b50e49169dfb72afe225672d 100644 (file)
@@ -17,6 +17,7 @@
                 SketchConstraintCoincidence SketchConstraintCoincidenceInternal
                 SketchConstraintMirror SketchConstraintAngle
                 SketchMultiRotation SketchMultiTranslation
+                SketchOffset
                 SketchConstraintCollinear SketchConstraintMiddle"
         when_nested="accept abort"
         title="Sketch"
         </integervalue>
         <validator id="PartSet_MultyTranslationSelection" />
       </feature>
+
+      <!-- Offset curve -->
+      <feature id="SketchOffset"
+               title="Offset"
+               tooltip="Offset a curve to a distance"
+               icon="icons/Sketch/offset.png"
+               helpfile="offsetFeature.html">
+        <sketch_multi_selector id="segments"
+                               label="Edges"
+                               tooltip="Select edges to offset"
+                               shape_types="Edges"
+                               use_external="true"
+                               greed="true">
+        </sketch_multi_selector>
+        <doublevalue id="offset_value"
+                     label="Offset value"
+                     tooltip="Offset value"
+                     default="1" min="0.000001"
+                     use_reset="false">
+          <validator id="GeomValidators_Positive" parameters="1"/>
+        </doublevalue>
+        <boolvalue id="reversed"
+                   label="Reversed"
+                   tooltip="Reverse the offset"
+                   default="false"
+                   obligatory="0"/>
+        <action id="add_wire"
+                label="Select wire"
+                tooltip="Add the list of segments conposing a wire with the selected items through the coincidence by boundary points"/>
+      </feature>
     </group>
 
     <group id="Dimensional constraints">