Salome HOME
2a7245e1dfc809d1f91407c2a691f97d4153d632
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Rigid.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Rigid.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Rigid.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <GeomAPI_Pnt.h>
12 #include <GeomAPI_Edge.h>
13 #include <GeomAPI_Curve.h>
14 #include <GeomAPI_Vertex.h>
15
16 #include <SketchPlugin_Constraint.h>
17
18 #include <AIS_Drawer.hxx>
19 #include <gp_Pnt2d.hxx>
20
21 #include <Graphic3d_AspectLine3d.hxx>
22 #include <Prs3d_Root.hxx>
23
24 #include <GeomAdaptor_Curve.hxx>
25 #include <BRep_Tool.hxx>
26 #include <StdPrs_DeflectionCurve.hxx>
27 #include <StdPrs_Point.hxx>
28 #include <Geom_CartesianPoint.hxx>
29
30
31
32 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
33 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
34
35 static Handle(Image_AlienPixMap) MyPixMap; 
36
37
38
39 SketcherPrs_Rigid::SketcherPrs_Rigid(ModelAPI_Feature* theConstraint, 
40                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
41  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
42 {
43   myPntArray = new Graphic3d_ArrayOfPoints(1);
44   myPntArray->AddVertex(0., 0., 0.);
45 }  
46
47
48 bool SketcherPrs_Rigid::updatePoints(double theStep) const 
49 {
50   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
51   if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
52     return false;
53
54   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
55   gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
56   myPntArray->SetVertice(1, aP1);
57   return true;
58 }
59
60
61 void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
62 {
63   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
64   std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
65   if (aShape.get() == NULL)
66     return;
67
68   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
69   if (aShape->isEdge()) {
70     Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
71     aGroup->SetPrimitivesAspect(aLineAspect);
72     std::shared_ptr<GeomAPI_Curve> aCurve = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
73     if (aCurve->isLine()) {
74       addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
75     } else {
76       GeomAdaptor_Curve aAdaptor(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
77       StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
78     }
79   } else {
80     // This is a point
81     Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
82     myDrawer->SetPointAspect(aPntAspect);
83
84     std::shared_ptr<GeomAPI_Vertex> aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
85     std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
86     Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
87     StdPrs_Point::Add(thePrs, aPoint, myDrawer);
88   }
89 }
90