From: azv Date: Thu, 26 Jun 2014 04:44:45 +0000 (+0400) Subject: Presentation for parallel and perpendicular constraints X-Git-Tag: V_0.4.4~223^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ad3c47dc4fecb938823b3f46edd351a36edc7ee1;p=modules%2Fshaper.git Presentation for parallel and perpendicular constraints --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index 91e6c4ca5..342b2c1de 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -6,7 +6,11 @@ #include #include -#include +#include + +#include +#include +#include SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel() { @@ -28,3 +32,50 @@ const boost::shared_ptr& SketchPlugin_ConstraintParallel::previe return getPreview(); } + +Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious) +{ + Handle(AIS_InteractiveObject) anAIS = thePrevious; + if (!sketch()) + return anAIS; + + boost::shared_ptr aData = data(); + boost::shared_ptr anAttr1 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::shared_ptr anAttr2 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + if (!anAttr1 || !anAttr1->isFeature() || + !anAttr2 || !anAttr2->isFeature()) + return anAIS; + boost::shared_ptr aLine1Feature = + boost::dynamic_pointer_cast(anAttr1->feature()); + boost::shared_ptr aLine2Feature = + boost::dynamic_pointer_cast(anAttr2->feature()); + if (!aLine1Feature || !aLine2Feature) + return anAIS; + + boost::shared_ptr aLine1 = aLine1Feature->preview(); + boost::shared_ptr aLine2 = aLine2Feature->preview(); + Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl()); + + if (anAIS.IsNull()) + { + Handle(AIS_ParallelRelation) aParallel = + new AIS_ParallelRelation(aLine1->impl(), aLine2->impl(), aPlane); + + anAIS = aParallel; + } + else + { + Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS); + if (!aParallel.IsNull()) + { + aParallel->SetFirstShape(aLine1->impl()); + aParallel->SetSecondShape(aLine2->impl()); + aParallel->SetPlane(aPlane); + aParallel->Redisplay(Standard_True); + } + } + return anAIS; +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index ac209b68f..eae4fcfbb 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -39,6 +39,9 @@ public: /// \brief Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& 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(); }; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index 85c543f2b..ca5e22972 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -6,7 +6,11 @@ #include #include -#include +#include + +#include +#include +#include SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular() { @@ -28,3 +32,49 @@ const boost::shared_ptr& SketchPlugin_ConstraintPerpendicular::p return getPreview(); } +Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious) +{ + Handle(AIS_InteractiveObject) anAIS = thePrevious; + if (!sketch()) + return anAIS; + + boost::shared_ptr aData = data(); + boost::shared_ptr anAttr1 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::shared_ptr anAttr2 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + if (!anAttr1 || !anAttr1->isFeature() || + !anAttr2 || !anAttr2->isFeature()) + return anAIS; + boost::shared_ptr aLine1Feature = + boost::dynamic_pointer_cast(anAttr1->feature()); + boost::shared_ptr aLine2Feature = + boost::dynamic_pointer_cast(anAttr2->feature()); + if (!aLine1Feature || !aLine2Feature) + return anAIS; + + boost::shared_ptr aLine1 = aLine1Feature->preview(); + boost::shared_ptr aLine2 = aLine2Feature->preview(); + Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl()); + + if (anAIS.IsNull()) + { + Handle(AIS_PerpendicularRelation) aPerpendicular = + new AIS_PerpendicularRelation(aLine1->impl(), aLine2->impl(), aPlane); + + anAIS = aPerpendicular; + } + else + { + Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS); + if (!aPerpendicular.IsNull()) + { + aPerpendicular->SetFirstShape(aLine1->impl()); + aPerpendicular->SetSecondShape(aLine2->impl()); + aPerpendicular->SetPlane(aPlane); + aPerpendicular->Redisplay(Standard_True); + } + } + return anAIS; +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index 475c33084..68b733e8c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -39,6 +39,9 @@ public: /// \brief Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& 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(); }; diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 0676bd58c..d54915677 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -209,11 +209,17 @@ bool SketchSolver_ConstraintGroup::changeConstraint( { // 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