From 0bdfa8968f3cded98aad14dc9cc475cdb59e81ce Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Mon, 25 May 2020 15:05:31 +0300 Subject: [PATCH] Task #3231: Sketcher Offset of a curve Implement the feature for the offset operation. --- src/SketchPlugin/CMakeLists.txt | 2 + src/SketchPlugin/SketchPlugin_Offset.cpp | 65 ++++++++++++++ src/SketchPlugin/SketchPlugin_Offset.h | 106 +++++++++++++++++++++++ src/SketchPlugin/SketchPlugin_Plugin.cpp | 4 + src/SketchPlugin/plugin-Sketch.xml | 31 +++++++ 5 files changed, 208 insertions(+) create mode 100644 src/SketchPlugin/SketchPlugin_Offset.cpp create mode 100644 src/SketchPlugin/SketchPlugin_Offset.h diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index f9ada5439..91056a0ed 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -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 index 000000000..269c25980 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Offset.cpp @@ -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 + +#include + +#include +#include +#include + + +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 index 000000000..19fff782a --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Offset.h @@ -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 +#include + +/**\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 diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 3d11107a7..3be8ffc56 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -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 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); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 8d111edbb..e7cb83553 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -17,6 +17,7 @@ SketchConstraintCoincidence SketchConstraintCoincidenceInternal SketchConstraintMirror SketchConstraintAngle SketchMultiRotation SketchMultiTranslation + SketchOffset SketchConstraintCollinear SketchConstraintMiddle" when_nested="accept abort" title="Sketch" @@ -938,6 +939,36 @@ + + + + + + + + + + + -- 2.30.2