Salome HOME
5158b932d181f143033f7f5ca29fbe9195019261
[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
29 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
30 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
31
32 static Handle(Image_AlienPixMap) MyPixMap;
33
34 SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* theConstraint, 
35                                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
36  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
37 {
38   myPntArray = new Graphic3d_ArrayOfPoints(2);
39   myPntArray->AddVertex(0., 0., 0.);
40   myPntArray->AddVertex(0., 0., 0.);
41 }  
42
43 void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
44                                    const Handle(Prs3d_Presentation)& thePresentation, 
45                                    const Standard_Integer theMode)
46 {
47   prepareAspect();
48
49   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
50   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
51
52   std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
53   if (aLine1.get() == NULL)
54     return;
55
56   std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
57   if (aLine2.get() == NULL)
58     return;
59
60   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
61   gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
62   gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
63
64   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
65   aGroup->SetPrimitivesAspect(myAspect);
66   myPntArray->SetVertice(1, aP1);
67   myPntArray->SetVertice(2, aP2);
68   aGroup->AddPrimitiveArray(myPntArray);
69 }
70
71 void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
72 {
73   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
74
75   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
76   aGroup->SetPrimitivesAspect(aLineAspect);
77
78   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
79   addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
80 }
81