Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Parallel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Parallel.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Parallel.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 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
36                                                       const std::string& theAttribute);
37
38
39 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, SketcherPrs_SymbolPrs);
40 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, SketcherPrs_SymbolPrs);
41
42 static Handle(Image_AlienPixMap) MyPixMap;
43
44 SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, 
45                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
46  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
47 {
48   myPntArray = new Graphic3d_ArrayOfPoints(2);
49   myPntArray->AddVertex(0., 0., 0.);
50   myPntArray->AddVertex(0. ,0., 0.);
51 }  
52
53 void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
54                                    const Handle(Prs3d_Presentation)& thePresentation, 
55                                    const Standard_Integer theMode)
56 {
57   prepareAspect();
58
59   std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
60   if (aLine1.get() == NULL)
61     return;
62
63   std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
64   if (aLine2.get() == NULL)
65     return;
66
67   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
68   gp_Pnt aP1 = aMgr->getPosition(aLine1, this);
69   gp_Pnt aP2 = aMgr->getPosition(aLine2, this);
70
71   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
72   aGroup->SetPrimitivesAspect(myAspect);
73   myPntArray->SetVertice(1, aP1);
74   myPntArray->SetVertice(2, aP2);
75   aGroup->AddPrimitiveArray(myPntArray);
76 }
77
78 void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
79                                             const Standard_Integer aMode)
80 {
81   ClearSelected();
82
83   Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
84   Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1));
85   Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2));
86   aSelection->Add(aSP1);
87   aSelection->Add(aSP2);
88 }
89
90 void SketcherPrs_Parallel::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, 
91                                            const SelectMgr_SequenceOfOwner& theOwners)
92 {
93
94   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
95   aSelectionPrs->Clear();
96   drawLines(aSelectionPrs, Quantity_NOC_WHITE);
97
98   aSelectionPrs->SetDisplayPriority(9);
99   aSelectionPrs->Display();
100   thePM->Highlight(this);
101 }
102
103 void SketcherPrs_Parallel::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, 
104                                                  const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
105 {
106   thePM->Color(this, theColor);
107
108   Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
109   aHilightPrs->Clear();
110   drawLines(aHilightPrs, theColor);
111
112   if (thePM->IsImmediateModeOn())
113     thePM->AddToImmediateList(aHilightPrs);
114 }
115
116
117 void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
118 {
119   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
120
121   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
122   aGroup->SetPrimitivesAspect(aLineAspect);
123
124   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
125   addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
126 }
127