Salome HOME
0c9e45da273a071f60fa41c1ec420809a31dc720
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Perpendicular.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Perpendicular.cpp
4 // Created:     12 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Perpendicular.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <GeomAPI_Pnt.h>
12
13 #include <SketchPlugin_Constraint.h>
14
15 #include <AIS_Drawer.hxx>
16 #include <gp_Pnt2d.hxx>
17
18 #include <Prs3d_PointAspect.hxx>
19 #include <Prs3d_Root.hxx>
20 #include <Prs3d_LineAspect.hxx>
21
22 #include <Graphic3d_MarkerImage.hxx>
23 #include <Graphic3d_AspectMarker3d.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
26
27
28 // Function which is defined in SketchPlugin_ConstraintDistance.cpp
29 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
30                                                       const std::string& theAttribute);
31
32
33
34 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
35 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
36
37 static Handle(Image_AlienPixMap) MyPixMap;
38
39 SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* theConstraint, 
40                                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
41  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
42 {
43   myPntArray = new Graphic3d_ArrayOfPoints(2);
44   myPntArray->AddVertex(0., 0., 0.);
45   myPntArray->AddVertex(0. ,0., 0.);
46 }  
47
48 void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
49                                    const Handle(Prs3d_Presentation)& thePresentation, 
50                                    const Standard_Integer theMode)
51 {
52   prepareAspect();
53
54   std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
55   if (aLine1.get() == NULL)
56     return;
57
58   std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
59   if (aLine2.get() == NULL)
60     return;
61
62   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
63   gp_Pnt aP1 = aMgr->getPosition(aLine1, this);
64   gp_Pnt aP2 = aMgr->getPosition(aLine2, this);
65
66   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
67   aGroup->SetPrimitivesAspect(myAspect);
68   myPntArray->SetVertice(1, aP1);
69   myPntArray->SetVertice(2, aP2);
70   aGroup->AddPrimitiveArray(myPntArray);
71 }
72
73 void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
74 {
75   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
76
77   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
78   aGroup->SetPrimitivesAspect(aLineAspect);
79
80   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
81   addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
82 }
83