Salome HOME
144664122a2f66c548dff867b47b31c527912322
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SymbolPrs.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_SymbolPrs.cpp
4 // Created:     12 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_SymbolPrs.h"
8 #include "SketcherPrs_Tools.h"
9
10 #include <GeomAPI_Edge.h>
11
12 #include <Graphic3d_ArrayOfSegments.hxx>
13
14
15 #ifdef WIN32
16 # define FSEP "\\"
17 #else
18 # define FSEP "/"
19 #endif
20
21 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
22 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
23
24
25 std::map<const char*, Handle(Image_AlienPixMap)> SketcherPrs_SymbolPrs::myIconsMap;
26
27
28 SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, 
29                                              const std::shared_ptr<GeomAPI_Ax3>& thePlane)
30  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
31 {
32   SetAutoHilight(Standard_False);
33 }
34
35 Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
36 {
37   if (myIconsMap.count(iconName()) == 1) {
38     return myIconsMap[iconName()];
39   }
40   TCollection_AsciiString aFile(getenv("NewGeomResources"));
41   aFile += FSEP;
42   aFile += iconName();
43   Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap();
44   if (aPixMap->Load(aFile)) {
45     myIconsMap[iconName()] = aPixMap;
46     return aPixMap;
47   }
48   return Handle(Image_AlienPixMap)();
49 }
50
51 void SketcherPrs_SymbolPrs::ClearSelected()
52 {
53   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );  
54   if( !aSelectionPrs.IsNull() ) {
55     aSelectionPrs->Clear(); 
56   }
57 }
58
59 void SketcherPrs_SymbolPrs::prepareAspect()
60 {
61   if (myAspect.IsNull()) {
62     myAspect = new Graphic3d_AspectMarker3d(icon());
63   }
64 }
65
66 void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const
67 {
68   std::shared_ptr<GeomAPI_Edge> aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName);
69   if (aLine.get() == NULL)
70     return;
71
72   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine->firstPoint();
73   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine->lastPoint();
74
75   Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1);
76   aLines->AddVertex(aPnt1->impl<gp_Pnt>());
77   aLines->AddVertex(aPnt2->impl<gp_Pnt>());
78   theGroup->AddPrimitiveArray(aLines);
79 }