Refactor MacroEllipse feature to produce several auxiliary features and one ellipse instead of a single feature with a lot of results.
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
SketchPlugin_ConstraintAngle.h
SketchPlugin_ConstraintBase.h
SketchPlugin_ConstraintCoincidence.h
+ SketchPlugin_ConstraintCoincidenceInternal.h
SketchPlugin_ConstraintCollinear.h
SketchPlugin_ConstraintDistance.h
SketchPlugin_ConstraintDistanceAlongDir.h
SketchPlugin_Constraint.cpp
SketchPlugin_ConstraintAngle.cpp
SketchPlugin_ConstraintCoincidence.cpp
+ SketchPlugin_ConstraintCoincidenceInternal.cpp
SketchPlugin_ConstraintCollinear.cpp
SketchPlugin_ConstraintDistance.cpp
SketchPlugin_ConstraintDistanceAlongDir.cpp
--- /dev/null
+// 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();
+}
--- /dev/null
+// 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
// 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<ResultPtr>& aResults = results();
- std::list<ResultPtr>::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);
}
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()) {
/// 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();
bool fillCharacteristicPoints();
void createEllipse(SketchPlugin_Sketch* theSketch, const int theResultIndex);
-
-private:
- std::set<ResultPtr> myAuxiliaryResults;
};
#endif
#include <SketchPlugin_MacroEllipse.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <SketchPlugin_Ellipse.h>
+#include <SketchPlugin_Line.h>
#include <SketchPlugin_MacroArcReentrantMessage.h>
+#include <SketchPlugin_Point.h>
#include <SketchPlugin_Tools.h>
#include <SketchPlugin_Sketch.h>
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<GeomDataAPI_Point2D>(theEllipsePoint);
+
+ AttributePoint2DPtr aCoord = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ 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<GeomDataAPI_Point2D>(theStartPoint);
+ AttributePoint2DPtr aEndPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theEndPoint);
+
+ AttributePoint2DPtr aLineStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aLineFeature->attribute(SketchPlugin_Line::START_ID()));
+ aLineStart->setValue(aStartPoint->x(), aStartPoint->y());
+
+ AttributePoint2DPtr aLineEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ 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();
#include <SketchPlugin_SketchEntity.h>
#include <GeomAPI_IPresentable.h>
-////class GeomAPI_Circ2d;
class GeomAPI_Pnt2d;
/**\class SketchPlugin_MacroEllipse
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<GeomAPI_Pnt2d> myCenter;
std::shared_ptr<GeomAPI_Pnt2d> myFocus;
#include <SketchPlugin_Projection.h>
#include <SketchPlugin_ConstraintAngle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <SketchPlugin_ConstraintCollinear.h>
#include <SketchPlugin_ConstraintDistance.h>
#include <SketchPlugin_ConstraintDistanceHorizontal.h>
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()) {
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);
}
// 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<GeomAPI_ICustomPrs> theDefaultPrs)
std::vector<int> aColor;
std::shared_ptr<ModelAPI_AttributeBoolean> 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");
}
SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical
SketchConstraintEqual SketchConstraintTangent
SketchFillet SketchSplit SketchTrim
- SketchConstraintCoincidence
+ SketchConstraintCoincidence SketchConstraintCoincidenceInternal
SketchConstraintMirror SketchConstraintAngle
SketchMultiRotation SketchMultiTranslation
SketchConstraintCollinear SketchConstraintMiddle"
</sketch_shape_selector>
<validator id="PartSet_CoincidentSelection"/>
</feature>
+ <!-- SketchConstraintCoincidenceInternal -->
+ <feature id="SketchConstraintCoincidenceInternal" title="Internal Coincidence" tooltip="Internal coincidence" icon="icons/Sketch/coincedence.png"
+ helpfile="coincedenceFeature.html" internal="1">
+ <sketch_shape_selector id="ConstraintEntityA" label="First object" tooltip="Select a first object" shape_types="vertex">
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+ </sketch_shape_selector>
+ <sketch_shape_selector id="ConstraintEntityB" label="Second object" tooltip="Select a second object" shape_types="vertex">
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
+ <validator id="SketchPlugin_CoincidenceAttr" parameters="ConstraintEntityA"/>
+ </sketch_shape_selector>
+ <validator id="PartSet_CoincidentSelection"/>
+ </feature>
<!-- SketchConstraintMiddle -->
<feature id="SketchConstraintMiddle" title="Middle point" tooltip="Create constraint for setting middle point on a line"
#include <SketchSolver_Constraint.h>
#include <SketchSolver_ConstraintAngle.h>
#include <SketchSolver_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <SketchSolver_ConstraintCollinear.h>
#include <SketchSolver_ConstraintDistance.h>
#include <SketchSolver_ConstraintEqual.h>
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));
#include <SketchSolver_Constraint.h>
#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <SketchPlugin_ConstraintCollinear.h>
#include <SketchPlugin_ConstraintMiddle.h>
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();
#include <SketchPlugin_ConstraintAngle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <SketchPlugin_ConstraintCollinear.h>
#include <SketchPlugin_ConstraintDistance.h>
#include <SketchPlugin_ConstraintEqual.h>
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;