From 5d382fc1e3be8c6362f8b03e437a054130f6db04 Mon Sep 17 00:00:00 2001 From: azv Date: Sun, 15 Sep 2019 14:08:47 +0300 Subject: [PATCH] Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003) Refactor MacroEllipse feature to produce several auxiliary features and one ellipse instead of a single feature with a lot of results. --- src/SketchAPI/SketchAPI_Ellipse.cpp | 2 + src/SketchPlugin/CMakeLists.txt | 2 + ...chPlugin_ConstraintCoincidenceInternal.cpp | 38 ++++++++++++ ...etchPlugin_ConstraintCoincidenceInternal.h | 59 ++++++++++++++++++ src/SketchPlugin/SketchPlugin_Ellipse.cpp | 27 +------- src/SketchPlugin/SketchPlugin_Ellipse.h | 6 -- .../SketchPlugin_MacroEllipse.cpp | 61 +++++++++++++++++++ src/SketchPlugin/SketchPlugin_MacroEllipse.h | 7 ++- src/SketchPlugin/SketchPlugin_Plugin.cpp | 4 ++ src/SketchPlugin/SketchPlugin_SketchEntity.h | 7 +-- src/SketchPlugin/plugin-Sketch.xml | 16 ++++- .../PlaneGCSSolver/PlaneGCSSolver_Tools.cpp | 4 +- .../PlaneGCSSolver_UpdateCoincidence.cpp | 2 + src/SketchSolver/SketchSolver_Constraint.cpp | 4 +- 14 files changed, 197 insertions(+), 42 deletions(-) create mode 100644 src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.cpp create mode 100644 src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.h diff --git a/src/SketchAPI/SketchAPI_Ellipse.cpp b/src/SketchAPI/SketchAPI_Ellipse.cpp index 40c5c4ab3..b601e6612 100644 --- a/src/SketchAPI/SketchAPI_Ellipse.cpp +++ b/src/SketchAPI/SketchAPI_Ellipse.cpp @@ -141,10 +141,12 @@ void SketchAPI_Ellipse::setMinorRadius(double theMinorRadius) ModelHighAPI_Selection SketchAPI_Ellipse::majorAxis() const { + return ModelHighAPI_Selection(); } ModelHighAPI_Selection SketchAPI_Ellipse::minorAxis() const { + return ModelHighAPI_Selection(); } void SketchAPI_Ellipse::dump(ModelHighAPI_Dumper& theDumper) const diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 26cf523f2..b304b4aad 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -28,6 +28,7 @@ SET(PROJECT_HEADERS SketchPlugin_ConstraintAngle.h SketchPlugin_ConstraintBase.h SketchPlugin_ConstraintCoincidence.h + SketchPlugin_ConstraintCoincidenceInternal.h SketchPlugin_ConstraintCollinear.h SketchPlugin_ConstraintDistance.h SketchPlugin_ConstraintDistanceAlongDir.h @@ -74,6 +75,7 @@ SET(PROJECT_SOURCES SketchPlugin_Constraint.cpp SketchPlugin_ConstraintAngle.cpp SketchPlugin_ConstraintCoincidence.cpp + SketchPlugin_ConstraintCoincidenceInternal.cpp SketchPlugin_ConstraintCollinear.cpp SketchPlugin_ConstraintDistance.cpp SketchPlugin_ConstraintDistanceAlongDir.cpp diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.cpp new file mode 100644 index 000000000..ccab1cf93 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 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 "SketchPlugin_ConstraintCoincidenceInternal.h" + +SketchPlugin_ConstraintCoincidenceInternal::SketchPlugin_ConstraintCoincidenceInternal() +{ +} + +void SketchPlugin_ConstraintCoincidenceInternal::initAttributes() +{ + SketchPlugin_ConstraintCoincidence::initAttributes(); +} + +void SketchPlugin_ConstraintCoincidenceInternal::execute() +{ +} + +AISObjectPtr SketchPlugin_ConstraintCoincidenceInternal::getAISObject(AISObjectPtr thePrevious) +{ + return AISObjectPtr(); +} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.h b/src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.h new file mode 100644 index 000000000..fac0060eb --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidenceInternal.h @@ -0,0 +1,59 @@ +// Copyright (C) 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 SketchPlugin_ConstraintCoincidenceInternal_H_ +#define SketchPlugin_ConstraintCoincidenceInternal_H_ + +#include "SketchPlugin.h" +#include "SketchPlugin_ConstraintCoincidence.h" + +/** \class SketchPlugin_ConstraintCoincidenceInternal + * \ingroup Plugins + * \brief Internal coincidence constraint not applicable for the end user + */ +class SketchPlugin_ConstraintCoincidenceInternal : public SketchPlugin_ConstraintCoincidence +{ + public: + /// Coincidence constraint kind + inline static const std::string& ID() + { + static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidenceInternal"); + return MY_CONSTRAINT_COINCIDENCE_ID; + } + /// \brief Returns the kind of a feature + SKETCHPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = SketchPlugin_ConstraintCoincidenceInternal::ID(); + return MY_KIND; + } + + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + + /// \brief Creates a new part document if needed + SKETCHPLUGIN_EXPORT virtual void execute(); + + /// \brief Request for initialization of data model of the feature: adding all attributes + SKETCHPLUGIN_EXPORT virtual void initAttributes(); + + /// \brief Use plugin manager for features creation + SketchPlugin_ConstraintCoincidenceInternal(); +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Ellipse.cpp b/src/SketchPlugin/SketchPlugin_Ellipse.cpp index 6e88c8191..af4f1bb4a 100644 --- a/src/SketchPlugin/SketchPlugin_Ellipse.cpp +++ b/src/SketchPlugin/SketchPlugin_Ellipse.cpp @@ -77,29 +77,9 @@ void SketchPlugin_Ellipse::execute() // Calculate all characteristics of the ellipse. fillCharacteristicPoints(); - // Make visible points related to ellipse characteristics. + // Make a visible center of the ellipse. int aResultIndex = 0; SketchPlugin_Sketch::createPoint2DResult(this, aSketch, CENTER_ID(), aResultIndex++); - SketchPlugin_Sketch::createPoint2DResult(this, aSketch, FIRST_FOCUS_ID(), aResultIndex++); - SketchPlugin_Sketch::createPoint2DResult(this, aSketch, SECOND_FOCUS_ID(), aResultIndex++); - SketchPlugin_Sketch::createPoint2DResult(this, aSketch, MAJOR_AXIS_START_ID(), aResultIndex++); - SketchPlugin_Sketch::createPoint2DResult(this, aSketch, MAJOR_AXIS_END_ID(), aResultIndex++); - SketchPlugin_Sketch::createPoint2DResult(this, aSketch, MINOR_AXIS_START_ID(), aResultIndex++); - SketchPlugin_Sketch::createPoint2DResult(this, aSketch, MINOR_AXIS_END_ID(), aResultIndex++); - - // Make auxiliary axes - SketchPlugin_Sketch::createLine2DResult(this, aSketch, - MAJOR_AXIS_START_ID(), MAJOR_AXIS_END_ID(), aResultIndex++); - SketchPlugin_Sketch::createLine2DResult(this, aSketch, - MINOR_AXIS_START_ID(), MINOR_AXIS_END_ID(), aResultIndex++); - - // Mark already created results auxiliary - myAuxiliaryResults.clear(); - const std::list& aResults = results(); - std::list::const_iterator anIt = aResults.begin(); - for (int anIndex = 0; anIt != aResults.end() && anIndex < aResultIndex; ++anIt, ++anIndex) - myAuxiliaryResults.insert(*anIt); - // Make a visible ellipse. createEllipse(aSketch, aResultIndex); } @@ -108,11 +88,6 @@ bool SketchPlugin_Ellipse::isFixed() { return data()->selection(EXTERNAL_ID())->context().get() != NULL; } -bool SketchPlugin_Ellipse::isAuxiliary(ResultPtr theResult) -{ - return myAuxiliaryResults.find(theResult) != myAuxiliaryResults.end(); -} - void SketchPlugin_Ellipse::attributeChanged(const std::string& theID) { // the second condition for unability to move external segments anywhere if (theID == EXTERNAL_ID() || isFixed()) { diff --git a/src/SketchPlugin/SketchPlugin_Ellipse.h b/src/SketchPlugin/SketchPlugin_Ellipse.h index bfa0478a7..35c88d111 100644 --- a/src/SketchPlugin/SketchPlugin_Ellipse.h +++ b/src/SketchPlugin/SketchPlugin_Ellipse.h @@ -116,9 +116,6 @@ class SketchPlugin_Ellipse: public SketchPlugin_SketchEntity /// Use plugin manager for features creation SketchPlugin_Ellipse(); - /// Returns \c true if the result is marked as auxiliary - virtual bool isAuxiliary(ResultPtr theResult); - protected: /// \brief Initializes attributes of derived class. virtual void initDerivedClassAttributes(); @@ -127,9 +124,6 @@ private: bool fillCharacteristicPoints(); void createEllipse(SketchPlugin_Sketch* theSketch, const int theResultIndex); - -private: - std::set myAuxiliaryResults; }; #endif diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp index 0b5ecf95c..6d5dd5741 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp @@ -19,8 +19,11 @@ #include +#include #include +#include #include +#include #include #include @@ -284,9 +287,67 @@ FeaturePtr SketchPlugin_MacroEllipse::createEllipseFeature() boolean(AUXILIARY_ID())->value()); aEllipseFeature->execute(); + + // create auxiliary points + createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID()), "FirstFocus"); + createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::SECOND_FOCUS_ID()), "SecondFocus"); + createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()), "MajorAxisNegative"); + createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()), "MajorAxisPositive"); + createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_START_ID()), "MinorAxisNegative"); + createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_END_ID()), "MinorAxisPositive"); + // create auxiliary axes + createAuxiliaryAxis(aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()), + aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID())); + createAuxiliaryAxis(aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_START_ID()), + aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_END_ID())); + return aEllipseFeature; } +void SketchPlugin_MacroEllipse::createAuxiliaryPoint(const AttributePtr& theEllipsePoint, + const std::string& theName) +{ + FeaturePtr aPointFeature = sketch()->addFeature(SketchPlugin_Point::ID()); + aPointFeature->data()->setName(theName); + aPointFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true); + + AttributePoint2DPtr anElPoint = std::dynamic_pointer_cast(theEllipsePoint); + + AttributePoint2DPtr aCoord = std::dynamic_pointer_cast( + aPointFeature->attribute(SketchPlugin_Point::COORD_ID())); + aCoord->setValue(anElPoint->x(), anElPoint->y()); + + createInternalConstraint(anElPoint, aCoord); +} + +void SketchPlugin_MacroEllipse::createAuxiliaryAxis(const AttributePtr& theStartPoint, + const AttributePtr& theEndPoint) +{ + FeaturePtr aLineFeature = sketch()->addFeature(SketchPlugin_Line::ID()); + aLineFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true); + + AttributePoint2DPtr aStartPoint = std::dynamic_pointer_cast(theStartPoint); + AttributePoint2DPtr aEndPoint = std::dynamic_pointer_cast(theEndPoint); + + AttributePoint2DPtr aLineStart = std::dynamic_pointer_cast( + aLineFeature->attribute(SketchPlugin_Line::START_ID())); + aLineStart->setValue(aStartPoint->x(), aStartPoint->y()); + + AttributePoint2DPtr aLineEnd = std::dynamic_pointer_cast( + aLineFeature->attribute(SketchPlugin_Line::END_ID())); + aLineEnd->setValue(aEndPoint->x(), aEndPoint->y()); + + createInternalConstraint(aStartPoint, aLineStart); + createInternalConstraint(aEndPoint, aLineEnd); +} + +void SketchPlugin_MacroEllipse::createInternalConstraint(const AttributePtr& thePoint1, + const AttributePtr& thePoint2) +{ + SketchPlugin_Tools::createConstraintAttrAttr( + sketch(), SketchPlugin_ConstraintCoincidenceInternal::ID(), thePoint1, thePoint2); +} + AISObjectPtr SketchPlugin_MacroEllipse::getAISObject(AISObjectPtr thePrevious) { SketchPlugin_Sketch* aSketch = sketch(); diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.h b/src/SketchPlugin/SketchPlugin_MacroEllipse.h index 5b7d2945a..ac087b055 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.h +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.h @@ -25,7 +25,6 @@ #include #include -////class GeomAPI_Circ2d; class GeomAPI_Pnt2d; /**\class SketchPlugin_MacroEllipse @@ -163,6 +162,12 @@ private: FeaturePtr createEllipseFeature(); + void createAuxiliaryPoint(const AttributePtr& theEllipsePoint, + const std::string& theName); + void createAuxiliaryAxis(const AttributePtr& theStartPoint, const AttributePtr& theEndPoint); + + void createInternalConstraint(const AttributePtr& thePoint1, const AttributePtr& thePoint2); + private: std::shared_ptr myCenter; std::shared_ptr myFocus; diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 3958b491c..38852d714 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -198,6 +199,8 @@ FeaturePtr SketchPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new SketchPlugin_Projection); } else if (theFeatureID == SketchPlugin_ConstraintCoincidence::ID()) { return FeaturePtr(new SketchPlugin_ConstraintCoincidence); + } else if (theFeatureID == SketchPlugin_ConstraintCoincidenceInternal::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintCoincidenceInternal); } else if (theFeatureID == SketchPlugin_ConstraintCollinear::ID()) { return FeaturePtr(new SketchPlugin_ConstraintCollinear); } else if (theFeatureID == SketchPlugin_ConstraintDistance::ID()) { @@ -296,6 +299,7 @@ std::shared_ptr SketchPlugin_Plugin aMsg->setState(SketchPlugin_Ellipse::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_Projection::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintCoincidenceInternal::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintCollinear::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane); aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane); diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index 1a736ad58..c207dd72b 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -112,10 +112,6 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC } // LCOV_EXCL_START - /// Returns \c true if the result is marked as auxiliary - virtual bool isAuxiliary(ResultPtr theResult) - { return false; } - /// Customize presentation of the feature virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theDefaultPrs) @@ -146,8 +142,7 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC std::vector aColor; std::shared_ptr anAuxiliaryAttr = data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID()); - bool isConstruction = (anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value()) - || isAuxiliary(theResult); + bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value(); if (isConstruction) { aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color"); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index e26d1dd44..9c930341c 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -13,7 +13,7 @@ SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical SketchConstraintEqual SketchConstraintTangent SketchFillet SketchSplit SketchTrim - SketchConstraintCoincidence + SketchConstraintCoincidence SketchConstraintCoincidenceInternal SketchConstraintMirror SketchConstraintAngle SketchMultiRotation SketchMultiTranslation SketchConstraintCollinear SketchConstraintMiddle" @@ -1049,6 +1049,20 @@ + + + + + + + + + + + + + #include #include +#include #include #include #include @@ -122,7 +123,8 @@ static GCS::SET_pD ellipseParameters(const EdgeWrapperPtr& theEllipse); SolverConstraintPtr PlaneGCSSolver_Tools::createConstraint(ConstraintPtr theConstraint) { - if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID() || + theConstraint->getKind() == SketchPlugin_ConstraintCoincidenceInternal::ID()) { return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint)); } else if (theConstraint->getKind() == SketchPlugin_ConstraintCollinear::ID()) { return SolverConstraintPtr(new SketchSolver_ConstraintCollinear(theConstraint)); diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp index 4ed6b81e9..1f0466486 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -48,6 +49,7 @@ void PlaneGCSSolver_UpdateCoincidence::attach(SketchSolver_Constraint* theObserv void PlaneGCSSolver_UpdateCoincidence::update(const FeaturePtr& theFeature) { if (theFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID() || + theFeature->getKind() == SketchPlugin_ConstraintCoincidenceInternal::ID() || theFeature->getKind() == SketchPlugin_ConstraintMiddle::ID() || theFeature->getKind() == SketchPlugin_ConstraintCollinear::ID()) { myCoincident.clear(); diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 7d047ac80..48c0fa5b8 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -76,7 +77,8 @@ void SketchSolver_Constraint::blockEvents(bool isBlocked) SketchSolver_ConstraintType SketchSolver_Constraint::TYPE(ConstraintPtr theConstraint) { const std::string& aType = theConstraint->getKind(); - if (aType == SketchPlugin_ConstraintCoincidence::ID()) + if (aType == SketchPlugin_ConstraintCoincidence::ID() || + aType == SketchPlugin_ConstraintCoincidenceInternal::ID()) return CONSTRAINT_COINCIDENCE; else if (aType == SketchPlugin_ConstraintRigid::ID()) return CONSTRAINT_FIXED; -- 2.39.2