#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
-#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Line.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_ParallelRelation.hxx>
+#include <Geom_Plane.hxx>
SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
{
return getPreview();
}
+
+Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious)
+{
+ Handle(AIS_InteractiveObject) anAIS = thePrevious;
+ if (!sketch())
+ return anAIS;
+
+ boost::shared_ptr<ModelAPI_Data> aData = data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+ if (!anAttr1 || !anAttr1->isFeature() ||
+ !anAttr2 || !anAttr2->isFeature())
+ return anAIS;
+ boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
+ boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
+ if (!aLine1Feature || !aLine2Feature)
+ return anAIS;
+
+ boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
+ boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
+ Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
+
+ if (anAIS.IsNull())
+ {
+ Handle(AIS_ParallelRelation) aParallel =
+ new AIS_ParallelRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
+
+ anAIS = aParallel;
+ }
+ else
+ {
+ Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS);
+ if (!aParallel.IsNull())
+ {
+ aParallel->SetFirstShape(aLine1->impl<TopoDS_Shape>());
+ aParallel->SetSecondShape(aLine2->impl<TopoDS_Shape>());
+ aParallel->SetPlane(aPlane);
+ aParallel->Redisplay(Standard_True);
+ }
+ }
+ return anAIS;
+}
+
/// \brief Returns the sketch preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+ /// Returns the AIS preview
+ SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
+
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintParallel();
};
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
-#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Line.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_PerpendicularRelation.hxx>
+#include <Geom_Plane.hxx>
SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
{
return getPreview();
}
+Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious)
+{
+ Handle(AIS_InteractiveObject) anAIS = thePrevious;
+ if (!sketch())
+ return anAIS;
+
+ boost::shared_ptr<ModelAPI_Data> aData = data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+ if (!anAttr1 || !anAttr1->isFeature() ||
+ !anAttr2 || !anAttr2->isFeature())
+ return anAIS;
+ boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
+ boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
+ if (!aLine1Feature || !aLine2Feature)
+ return anAIS;
+
+ boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
+ boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
+ Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
+
+ if (anAIS.IsNull())
+ {
+ Handle(AIS_PerpendicularRelation) aPerpendicular =
+ new AIS_PerpendicularRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
+
+ anAIS = aPerpendicular;
+ }
+ else
+ {
+ Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+ if (!aPerpendicular.IsNull())
+ {
+ aPerpendicular->SetFirstShape(aLine1->impl<TopoDS_Shape>());
+ aPerpendicular->SetSecondShape(aLine2->impl<TopoDS_Shape>());
+ aPerpendicular->SetPlane(aPlane);
+ aPerpendicular->Redisplay(Standard_True);
+ }
+ }
+ return anAIS;
+}
+
/// \brief Returns the sketch preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+ /// Returns the AIS preview
+ SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
+
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintPerpendicular();
};
{
// Several points may be coincident, it is not necessary to store all constraints between them.
// Try to find sequence of coincident points which connects the points of new constraint
- if (aConstrType == SLVS_C_POINTS_COINCIDENT &&
- !addCoincidentPoints(aConstrEnt[0], aConstrEnt[1]))
+ if (aConstrType == SLVS_C_POINTS_COINCIDENT)
{
- myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes
- return false;
+ if (aConstrEnt[0] == aConstrEnt[1]) // no need to add self coincidence
+ {
+ return false;
+ }
+ if (!addCoincidentPoints(aConstrEnt[0], aConstrEnt[1]))
+ {
+ myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes
+ return false;
+ }
}
// Create SolveSpace constraint structure