Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom 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
10 #include <GeomAPI_Pnt.h>
11
12 #include <SketchPlugin_Constraint.h>
13
14 #include <AIS_Drawer.hxx>
15 #include <Graphic3d_AspectMarker3d.hxx>
16 #include <Prs3d_PointAspect.hxx>
17 #include <Prs3d_Root.hxx>
18 #include <gp_Pnt2d.hxx>
19 #include <Image_AlienPixMap.hxx>
20 #include <Graphic3d_MarkerImage.hxx>
21 #include <SelectMgr_EntityOwner.hxx>
22 #include <Select3D_SensitivePoint.hxx>
23 #include <SelectMgr_Selection.hxx>
24 #include <Select3D_SensitiveSegment.hxx>
25
26 extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
27                                                       const std::string& theAttribute);
28
29 #ifdef WIN32
30 # define FSEP "\\"
31 #else
32 # define FSEP "/"
33 #endif
34
35
36 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject);
37 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject);
38
39 static Handle(Image_AlienPixMap) MyPixMap;
40
41 SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, 
42                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
43  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
44 {
45   if (MyPixMap.IsNull()) {
46     TCollection_AsciiString aFile(getenv("NewGeomResources"));
47     aFile += FSEP;
48     aFile += "parallel.png";
49     MyPixMap = new Image_AlienPixMap();
50     if (!MyPixMap->Load(aFile))
51       MyPixMap.Nullify();
52   }
53   if (!MyPixMap.IsNull()) {
54     myAspect = new Graphic3d_AspectMarker3d(MyPixMap);
55     myPntArray = new Graphic3d_ArrayOfPoints(2);
56     myPntArray->AddVertex(0., 0., 0.);
57     myPntArray->AddVertex(0. ,0., 0.);
58   }
59 }  
60
61 void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
62                                    const Handle(Prs3d_Presentation)& thePresentation, 
63                                    const Standard_Integer theMode)
64 {
65   if (myAspect.IsNull())
66     return;
67
68   std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
69   if (aLine1.get() == NULL)
70     return;
71
72   std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
73   if (aLine2.get() == NULL)
74     return;
75
76   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
77   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
78   gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
79              (aPnt1->y() + aPnt2->y())/2.,
80              (aPnt1->z() + aPnt2->z())/2.);
81
82   gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
83   gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
84   aShift.Normalize();
85   aShift.Multiply(20);
86   aP1.Translate(aShift);
87
88   aPnt1 = aLine2->firstPoint();
89   aPnt2 = aLine2->lastPoint();
90   gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
91              (aPnt1->y() + aPnt2->y())/2.,
92              (aPnt1->z() + aPnt2->z())/2.);
93
94   gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
95   aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
96   aShift.Normalize();
97   aShift.Multiply(20);
98   aP2.Translate(aShift);
99
100   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
101   aGroup->SetPrimitivesAspect(myAspect);
102   myPntArray->SetVertice(1, aP1);
103   myPntArray->SetVertice(2, aP2);
104   aGroup->AddPrimitiveArray(myPntArray);
105 }
106
107 void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
108                                             const Standard_Integer aMode)
109 {
110   std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
111   if (aLine1.get() == NULL)
112     return;
113
114   std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
115   if (aLine2.get() == NULL)
116     return;
117
118   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
119   Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(1));
120   Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(2));
121   aSelection->Add(aSP1);
122   aSelection->Add(aSP2);
123 }
124