]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Perpendicular.cpp
Salome HOME
Position manager created
[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 #include <Select3D_SensitivePoint.hxx>
28 #include <Select3D_SensitiveSegment.hxx>
29
30 #include <SelectMgr_SequenceOfOwner.hxx>
31 #include <SelectMgr_Selection.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
33
34
35 // Function which is defined in SketchPlugin_ConstraintDistance.cpp
36 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
37                                                       const std::string& theAttribute);
38
39
40
41 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
42 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
43
44 static Handle(Image_AlienPixMap) MyPixMap;
45
46 SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* theConstraint, 
47                                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
48  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
49 {
50   myPntArray = new Graphic3d_ArrayOfPoints(2);
51   myPntArray->AddVertex(0., 0., 0.);
52   myPntArray->AddVertex(0. ,0., 0.);
53 }  
54
55 void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
56                                    const Handle(Prs3d_Presentation)& thePresentation, 
57                                    const Standard_Integer theMode)
58 {
59   prepareAspect();
60
61   std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
62   if (aLine1.get() == NULL)
63     return;
64
65   std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
66   if (aLine2.get() == NULL)
67     return;
68
69   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
70   gp_Pnt aP1 = aMgr->getPosition(aLine1, this);
71   gp_Pnt aP2 = aMgr->getPosition(aLine2, this);
72   //std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
73   //std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
74   //gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
75   //           (aPnt1->y() + aPnt2->y())/2.,
76   //           (aPnt1->z() + aPnt2->z())/2.);
77
78   //gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
79   //gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
80   //aShift.Normalize();
81   //aShift.Multiply(20);
82   //aP1.Translate(aShift);
83
84   //aPnt1 = aLine2->firstPoint();
85   //aPnt2 = aLine2->lastPoint();
86   //gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
87   //           (aPnt1->y() + aPnt2->y())/2.,
88   //           (aPnt1->z() + aPnt2->z())/2.);
89
90   //gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
91   //aShift = aVec2.Crossed(myPlane->norm()->impl<gp_Dir>());
92   //aShift.Normalize();
93   //aShift.Multiply(20);
94   //aP2.Translate(aShift);
95
96   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
97   aGroup->SetPrimitivesAspect(myAspect);
98   myPntArray->SetVertice(1, aP1);
99   myPntArray->SetVertice(2, aP2);
100   aGroup->AddPrimitiveArray(myPntArray);
101 }
102
103 void SketcherPrs_Perpendicular::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
104                                             const Standard_Integer aMode)
105 {
106   ClearSelected();
107
108   Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
109   Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1));
110   Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2));
111   aSelection->Add(aSP1);
112   aSelection->Add(aSP2);
113 }
114
115 void SketcherPrs_Perpendicular::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
116                                            const SelectMgr_SequenceOfOwner& theOwners)
117 {
118
119   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
120   aSelectionPrs->Clear();
121   drawLines(aSelectionPrs, Quantity_NOC_WHITE);
122
123   aSelectionPrs->SetDisplayPriority(9);
124   aSelectionPrs->Display();
125   thePM->Highlight(this);
126 }
127
128 void SketcherPrs_Perpendicular::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
129                                                  const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
130 {
131   thePM->Color(this, theColor);
132
133   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
134   aHilightPrs->Clear();
135   drawLines(aHilightPrs, theColor);
136
137   if (thePM->IsImmediateModeOn())
138     thePM->AddToImmediateList(aHilightPrs);
139 }
140
141
142 void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
143 {
144   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
145
146   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
147   aGroup->SetPrimitivesAspect(aLineAspect);
148
149   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
150   addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
151 }
152