SketchPlugin_ConstraintPerpendicular.h
SketchPlugin_ConstraintRadius.h
SketchPlugin_ConstraintRigid.h
+ SketchPlugin_ConstraintHorizontal.h
+ SketchPlugin_ConstraintVertical.h
SketchPlugin_ShapeValidator.h
SketchPlugin_Validators.h
SketchPlugin_ResultValidators.h
SketchPlugin_ConstraintPerpendicular.cpp
SketchPlugin_ConstraintRadius.cpp
SketchPlugin_ConstraintRigid.cpp
+ SketchPlugin_ConstraintHorizontal.cpp
+ SketchPlugin_ConstraintVertical.cpp
SketchPlugin_ShapeValidator.cpp
SketchPlugin_Validators.cpp
SketchPlugin_ResultValidators.cpp
TestConstraintPerpendicular.py
TestConstraintRadius.py
TestConstraintRigid.py
+ TestConstraintHorizontal.py
+ TestConstraintVertical.py
TestHighload.py
TestSnowflake.py)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_ConstraintHorizontal.cpp
+// Created: 16 Mar 2015
+// Author: Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintHorizontal.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <SketcherPrs_Factory.h>
+
+#include <Config_PropManager.h>
+
+SketchPlugin_ConstraintHorizontal::SketchPlugin_ConstraintHorizontal()
+{
+}
+
+void SketchPlugin_ConstraintHorizontal::initAttributes()
+{
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintHorizontal::execute()
+{
+}
+
+AISObjectPtr SketchPlugin_ConstraintHorizontal::getAISObject(AISObjectPtr thePrevious)
+{
+ if (!sketch())
+ return thePrevious;
+
+ AISObjectPtr anAIS = thePrevious;
+ /// TODO: Horizontal constraint presentation should be put here
+ return anAIS;
+}
+
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_ConstraintHorizontal.h
+// Created: 16 Mar 2015
+// Author: Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintHorizontal_H_
+#define SketchPlugin_ConstraintHorizontal_H_
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
+#include "SketchPlugin_ConstraintBase.h"
+
+/** \class SketchPlugin_ConstraintHorizontal
+ * \ingroup Plugins
+ * \brief Feature for creation of a new constraint horizontality of a line
+ *
+ * This constraint has one attribute SketchPlugin_Constraint::ENTITY_A(),
+ * which specifies a line to be horizontal
+ */
+class SketchPlugin_ConstraintHorizontal : public SketchPlugin_ConstraintBase
+{
+ public:
+ /// Horizontal constraint kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_CONSTRAINT_HORIZONTAL_ID("SketchConstraintHorizontal");
+ return MY_CONSTRAINT_HORIZONTAL_ID;
+ }
+ /// \brief Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = SketchPlugin_ConstraintHorizontal::ID();
+ return MY_KIND;
+ }
+
+ /// \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();
+
+ /// Returns the AIS preview
+ SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+ /// \brief Use plugin manager for features creation
+ SketchPlugin_ConstraintHorizontal();
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_ConstraintVertical.cpp
+// Created: 16 Mar 2015
+// Author: Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintVertical.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <SketcherPrs_Factory.h>
+
+#include <Config_PropManager.h>
+
+SketchPlugin_ConstraintVertical::SketchPlugin_ConstraintVertical()
+{
+}
+
+void SketchPlugin_ConstraintVertical::initAttributes()
+{
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintVertical::execute()
+{
+}
+
+AISObjectPtr SketchPlugin_ConstraintVertical::getAISObject(AISObjectPtr thePrevious)
+{
+ if (!sketch())
+ return thePrevious;
+
+ AISObjectPtr anAIS = thePrevious;
+ /// TODO: Horizontal constraint presentation should be put here
+ return anAIS;
+}
+
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_ConstraintVertical.h
+// Created: 16 Mar 2015
+// Author: Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintVertical_H_
+#define SketchPlugin_ConstraintVertical_H_
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
+#include "SketchPlugin_ConstraintBase.h"
+
+/** \class SketchPlugin_ConstraintVertical
+ * \ingroup Plugins
+ * \brief Feature for creation of a new constraint verticality of a line
+ *
+ * This constraint has one attribute SketchPlugin_Constraint::ENTITY_A(),
+ * which specifies a line to be vertical
+ */
+class SketchPlugin_ConstraintVertical : public SketchPlugin_ConstraintBase
+{
+ public:
+ /// Vertical constraint kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_CONSTRAINT_VERTICAL_ID("SketchConstraintVertical");
+ return MY_CONSTRAINT_VERTICAL_ID;
+ }
+ /// \brief Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = SketchPlugin_ConstraintVertical::ID();
+ return MY_KIND;
+ }
+
+ /// \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();
+
+ /// Returns the AIS preview
+ SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+ /// \brief Use plugin manager for features creation
+ SketchPlugin_ConstraintVertical();
+};
+
+#endif
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintPerpendicular.h>
#include <SketchPlugin_ConstraintRadius.h>
#include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintVertical.h>
#include <SketchPlugin_Validators.h>
#include <SketchPlugin_ResultValidators.h>
#include <SketchPlugin_ShapeValidator.h>
return FeaturePtr(new SketchPlugin_ConstraintRadius);
} else if (theFeatureID == SketchPlugin_ConstraintRigid::ID()) {
return FeaturePtr(new SketchPlugin_ConstraintRigid);
+ } else if (theFeatureID == SketchPlugin_ConstraintHorizontal::ID()) {
+ return FeaturePtr(new SketchPlugin_ConstraintHorizontal);
+ } else if (theFeatureID == SketchPlugin_ConstraintVertical::ID()) {
+ return FeaturePtr(new SketchPlugin_ConstraintVertical);
}
// feature of such kind is not found
return FeaturePtr();
aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintHorizontal::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintVertical::ID(), aHasSketchPlane);
}
}
return aMsg;
--- /dev/null
+"""
+ TestConstraintHorizontal.py
+ Unit test of SketchPlugin_ConstraintHorizontal class
+
+ SketchPlugin_ConstraintHorizontal
+ static const std::string MY_CONSTRAINT_HORIZONTAL_ID("SketchConstraintHorizontal");
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+
+"""
+from GeomDataAPI import *
+from ModelAPI import *
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+__updated__ = "2015-03-16"
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
+diry.setValue(0, 1, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+#=========================================================================
+# Create non-horizontal line
+#=========================================================================
+aSession.startOperation()
+aSketchLine = aSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+aLineStartPoint.setValue(0., 15.)
+aLineEndPoint.setValue(20., 25.)
+aSession.finishOperation()
+#=========================================================================
+# Assign horizontal constraint for a line
+#=========================================================================
+aSession.startOperation()
+aHorizontalConstraint = aSketchFeature.addFeature("SketchConstraintHorizontal")
+refattrA = aHorizontalConstraint.refattr("ConstraintEntityA")
+aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
+assert (aResult is not None)
+refattrA.setObject(aResult)
+aHorizontalConstraint.execute()
+aSession.finishOperation()
+assert(aLineStartPoint.y() == aLineEndPoint.y())
+#=========================================================================
+# Move one of boundary points of a line
+#=========================================================================
+deltaX = deltaY = 10.
+aSession.startOperation()
+aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
+ aLineStartPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.y() == aLineEndPoint.y())
+#=========================================================================
+# Move other boundary point of a line
+#=========================================================================
+deltaX = -3.
+deltaY = -10.
+aSession.startOperation()
+aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
+ aLineEndPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.y() == aLineEndPoint.y())
+#=========================================================================
+# End of test
+#=========================================================================
--- /dev/null
+"""
+ TestConstraintVertical.py
+ Unit test of SketchPlugin_ConstraintVertical class
+
+ SketchPlugin_ConstraintVertical
+ static const std::string MY_CONSTRAINT_VERTICAL_ID("SketchConstraintVertical");
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+
+"""
+from GeomDataAPI import *
+from ModelAPI import *
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+__updated__ = "2015-03-16"
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
+diry.setValue(0, 1, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+#=========================================================================
+# Create non-vertical line
+#=========================================================================
+aSession.startOperation()
+aSketchLine = aSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+aLineStartPoint.setValue(0., 15.)
+aLineEndPoint.setValue(20., 25.)
+aSession.finishOperation()
+#=========================================================================
+# Assign vertical constraint for a line
+#=========================================================================
+aSession.startOperation()
+aVerticalConstraint = aSketchFeature.addFeature("SketchConstraintVertical")
+refattrA = aVerticalConstraint.refattr("ConstraintEntityA")
+aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
+assert (aResult is not None)
+refattrA.setObject(aResult)
+aVerticalConstraint.execute()
+aSession.finishOperation()
+assert(aLineStartPoint.x() == aLineEndPoint.x())
+#=========================================================================
+# Move one of boundary points of a line
+#=========================================================================
+deltaX = deltaY = 10.
+aSession.startOperation()
+aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
+ aLineStartPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.x() == aLineEndPoint.x())
+#=========================================================================
+# Move other boundary point of a line
+#=========================================================================
+deltaX = -3.
+deltaY = -10.
+aSession.startOperation()
+aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
+ aLineEndPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.x() == aLineEndPoint.x())
+#=========================================================================
+# End of test
+#=========================================================================
<group id="Basic">
<feature
id="Sketch"
- nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid"
+ nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical"
when_nested="accept abort"
title="Sketch"
tooltip="Create a new sketch"
</shape_selector>
<validator id="PartSet_RigidValidator"/>
</feature>
+ <!-- SketchConstraintHorizontal -->
+ <feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line">
+ <sketch_constraint_shape_selector id="ConstraintEntityA"
+ label="Line" tooltip="Select a line" shape_types="edge">
+ <selection_filter id="EdgeFilter" parameters="line"/>
+ </sketch_constraint_shape_selector>
+ </feature>
+ <!-- SketchConstraintVertical -->
+ <feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line">
+ <sketch_constraint_shape_selector id="ConstraintEntityA"
+ label="Line" tooltip="Select a line" shape_types="edge">
+ <selection_filter id="EdgeFilter" parameters="line"/>
+ </sketch_constraint_shape_selector>
+ </feature>
</group>
</workbench>
</plugin>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintPerpendicular.h>
#include <SketchPlugin_ConstraintRadius.h>
#include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintVertical.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Data.h>
return getType();
}
+ // Constraint for horizontal/vertical line
+ bool isHorizontal = (aConstraintKind.compare(SketchPlugin_ConstraintHorizontal::ID()) == 0);
+ bool isVertical = (aConstraintKind.compare(SketchPlugin_ConstraintVertical::ID()) == 0);
+ if (isHorizontal || isVertical) {
+ int aNbEntities = 2; // lines in SolveSpace constraints should start from SketchPlugin_Constraint::ENTITY_C() attribute
+ for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
+ std::shared_ptr<ModelAPI_Attribute> anAttr =
+ aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
+ if (typeOfAttribute(anAttr) == LINE)
+ myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+ }
+ if (aNbEntities == 3)
+ myType = isHorizontal ? SLVS_C_HORIZONTAL : SLVS_C_VERTICAL;
+ return getType();
+ }
+
/// \todo Implement other kind of constraints
return getType();