From: vsv Date: Tue, 17 Mar 2015 09:47:40 +0000 (+0300) Subject: Improve rigid constraint presentation X-Git-Tag: V_1.1.0~122^2~2^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1c0c005d8183e90aa20a076d64a89d5cfd4479f6;p=modules%2Fshaper.git Improve rigid constraint presentation --- diff --git a/src/GeomAPI/GeomAPI_Curve.cpp b/src/GeomAPI/GeomAPI_Curve.cpp index 9b4f4e26d..46a1ea19f 100644 --- a/src/GeomAPI/GeomAPI_Curve.cpp +++ b/src/GeomAPI/GeomAPI_Curve.cpp @@ -5,6 +5,7 @@ // Author: Mikhail PONIKAROV #include +#include #include #include @@ -13,11 +14,12 @@ #include #include #include +#include #define MY_CURVE (*(static_cast(myImpl))) GeomAPI_Curve::GeomAPI_Curve() - : GeomAPI_Interface(new Handle_Geom_Curve()) + : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1) { } @@ -27,8 +29,7 @@ GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr& theShape) const TopoDS_Shape& aShape = theShape->impl(); TopoDS_Edge anEdge = TopoDS::Edge(aShape); if (!anEdge.IsNull()) { - Standard_Real aStart, anEnd; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aStart, anEnd); + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd); if (!aCurve.IsNull()) { setImpl(new Handle(Geom_Curve)(aCurve)); } @@ -49,3 +50,10 @@ bool GeomAPI_Curve::isCircle() const { return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle); } + +std::shared_ptr GeomAPI_Curve::getPoint(double theParam) +{ + GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd); + gp_Pnt aPnt = aAdaptor.Value(theParam); + return std::shared_ptr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z())); +} diff --git a/src/GeomAPI/GeomAPI_Curve.h b/src/GeomAPI/GeomAPI_Curve.h index f09654a8c..20e0f0a46 100644 --- a/src/GeomAPI/GeomAPI_Curve.h +++ b/src/GeomAPI/GeomAPI_Curve.h @@ -10,6 +10,8 @@ #include #include +class GeomAPI_Pnt; + /**\class GeomAPI_Curve * \ingroup DataModel * \brief Interface to the generic curve object @@ -33,6 +35,19 @@ class GEOMAPI_EXPORT GeomAPI_Curve : public GeomAPI_Interface /// Returns whether the curve is circular virtual bool isCircle() const; + /// Returns start parameter of the curve + double startParam() const { return myStart; } + + /// Returns end parameter of the curve + double endParam() const { return myEnd; } + + /// Returns point on the curve by parameter + /// \param theParam parameter on the curve + std::shared_ptr getPoint(double theParam); + +private: + double myStart; + double myEnd; }; #endif diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.cpp b/src/SketcherPrs/SketcherPrs_HVDirection.cpp index 0ad7c1f15..13b3def6e 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.cpp +++ b/src/SketcherPrs/SketcherPrs_HVDirection.cpp @@ -57,7 +57,7 @@ void SketcherPrs_HVDirection::Compute(const Handle(PrsMgr_PresentationManager3d) prepareAspect(); ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(aObj1); + std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); if (aLine1.get() == NULL) return; diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index 09aebca45..b3bd0ffa9 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -59,11 +59,11 @@ void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& t ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(aObj1); + std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); if (aLine1.get() == NULL) return; - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(aObj2); + std::shared_ptr aLine2 = SketcherPrs_Tools::getShape(aObj2); if (aLine2.get() == NULL) return; diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index 287c5fe69..303daffeb 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -54,11 +54,11 @@ void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3 ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(aObj1); + std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); if (aLine1.get() == NULL) return; - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(aObj2); + std::shared_ptr aLine2 = SketcherPrs_Tools::getShape(aObj2); if (aLine2.get() == NULL) return; diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 36c5a72b2..03fb8a9b2 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -8,6 +8,9 @@ #include "SketcherPrs_Tools.h" #include +#include +#include +#include static const int MyStep = 20; @@ -46,27 +49,51 @@ int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, } } -gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theLine, +gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, Handle(SketcherPrs_SymbolPrs) thePrs) { - std::shared_ptr aShape = SketcherPrs_Tools::getLine(theLine); - std::shared_ptr aEdge = - std::shared_ptr(new GeomAPI_Edge(aShape)); + std::shared_ptr aShape = SketcherPrs_Tools::getShape(theShape); + gp_Pnt aP; // Central point + gp_Vec aVec1; // main vector + if (aShape->isEdge()) { + std::shared_ptr aCurve = std::shared_ptr(new GeomAPI_Curve(aShape)); + std::shared_ptr aPnt1; // Start point of main vector + std::shared_ptr aPnt2; // End point of main vector + if (aCurve->isLine()) { + std::shared_ptr aEdge = + std::shared_ptr(new GeomAPI_Edge(aShape)); + + aPnt1 = aEdge->firstPoint(); + aPnt2 = aEdge->lastPoint(); + + // Find the middle point + aP = gp_Pnt((aPnt1->x() + aPnt2->x())/2., + (aPnt1->y() + aPnt2->y())/2., + (aPnt1->z() + aPnt2->z())/2.); - std::shared_ptr aPnt1 = aEdge->firstPoint(); - std::shared_ptr aPnt2 = aEdge->lastPoint(); + } else { + double aMidParam = (aCurve->startParam() + aCurve->endParam()) / 2.; + std::shared_ptr aPnt = aCurve->getPoint(aMidParam); + aP = aPnt->impl(); - // Find the middle point - gp_Pnt aP((aPnt1->x() + aPnt2->x())/2., - (aPnt1->y() + aPnt2->y())/2., - (aPnt1->z() + aPnt2->z())/2.); + aPnt1 = aCurve->getPoint((aMidParam + aCurve->endParam()) / 2.); + aPnt2 = aCurve->getPoint((aMidParam + aCurve->startParam()) / 2.); + } + aVec1 = gp_Vec(aPnt1->impl(), aPnt2->impl()); + } else { + // This is a point + std::shared_ptr aVertex = std::shared_ptr(new GeomAPI_Vertex(aShape)); + std::shared_ptr aPnt = aVertex->point(); + aP = aPnt->impl(); - gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); + std::shared_ptr aDir = thePrs->plane()->dirX(); + aVec1 = gp_Vec(aDir->impl()); + } gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl()); aShift.Normalize(); aShift.Multiply(MyStep); - int aPos = getPositionIndex(theLine, thePrs); + int aPos = getPositionIndex(theShape, thePrs); int aM = 1; if ((aPos % 2) == 0) { // Even position diff --git a/src/SketcherPrs/SketcherPrs_Rigid.cpp b/src/SketcherPrs/SketcherPrs_Rigid.cpp index 099096c20..c436e586a 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.cpp +++ b/src/SketcherPrs/SketcherPrs_Rigid.cpp @@ -9,6 +9,9 @@ #include "SketcherPrs_PositionMgr.h" #include +#include +#include +#include #include @@ -31,6 +34,12 @@ #include #include +#include +#include +#include +#include +#include + extern std::shared_ptr getFeaturePoint(DataPtr theData, const std::string& theAttribute); @@ -56,7 +65,7 @@ void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& theP prepareAspect(); ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(aObj1); + std::shared_ptr aLine1 = SketcherPrs_Tools::getShape(aObj1); if (aLine1.get() == NULL) return; @@ -71,11 +80,31 @@ void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& theP void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const { - Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs); - - Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); - aGroup->SetPrimitivesAspect(aLineAspect); + ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr aShape = SketcherPrs_Tools::getShape(aObj); + if (aShape.get() == NULL) + return; - addLine(aGroup, SketchPlugin_Constraint::ENTITY_A()); + Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs); + if (aShape->isEdge()) { + Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2); + aGroup->SetPrimitivesAspect(aLineAspect); + std::shared_ptr aCurve = std::shared_ptr(new GeomAPI_Curve(aShape)); + if (aCurve->isLine()) { + addLine(aGroup, SketchPlugin_Constraint::ENTITY_A()); + } else { + GeomAdaptor_Curve aAdaptor(aCurve->impl(), aCurve->startParam(), aCurve->endParam()); + StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer); + } + } else { + // This is a point + Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1); + myDrawer->SetPointAspect(aPntAspect); + + std::shared_ptr aVertex = std::shared_ptr(new GeomAPI_Vertex(aShape)); + std::shared_ptr aPnt = aVertex->point(); + Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl()); + StdPrs_Point::Add(thePrs, aPoint, myDrawer); + } } diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index 9e051971a..b953501fa 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -71,7 +71,7 @@ void SketcherPrs_SymbolPrs::prepareAspect() void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const { ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, theAttrName); - std::shared_ptr aLine = SketcherPrs_Tools::getLine(aObj); + std::shared_ptr aLine = SketcherPrs_Tools::getShape(aObj); if (aLine.get() == NULL) return; std::shared_ptr aEdge = std::shared_ptr(new GeomAPI_Edge(aLine)); diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index e92283e42..9f845f57f 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -27,7 +27,7 @@ ObjectPtr getResult(SketchPlugin_Constraint* theFeature, const std::string& theA } -std::shared_ptr getLine(ObjectPtr theObject) +std::shared_ptr getShape(ObjectPtr theObject) { ResultConstructionPtr aRes = std::dynamic_pointer_cast(theObject); if (aRes.get() != NULL) { diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index e913a2fd6..3cde3ea2a 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -20,7 +20,7 @@ namespace SketcherPrs_Tools { ObjectPtr getResult(SketchPlugin_Constraint* theFeature, const std::string& theAttrName); - std::shared_ptr getLine(ObjectPtr theObject); + std::shared_ptr getShape(ObjectPtr theObject); std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, const std::string& theAttrName);