]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_SymbolPrs.cpp
Salome HOME
Position manager created
[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
36 Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
37 {
38   if (myIconsMap.count(iconName()) == 1) {
39     return myIconsMap[iconName()];
40   }
41   TCollection_AsciiString aFile(getenv("NewGeomResources"));
42   aFile += FSEP;
43   aFile += iconName();
44   Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap();
45   if (aPixMap->Load(aFile)) {
46     myIconsMap[iconName()] = aPixMap;
47     return aPixMap;
48   }
49   return Handle(Image_AlienPixMap)();
50 }
51
52 void SketcherPrs_SymbolPrs::ClearSelected()
53 {
54   Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL );  
55   if( !aSelectionPrs.IsNull() ) {
56     aSelectionPrs->Clear(); 
57   }
58 }
59
60 void SketcherPrs_SymbolPrs::prepareAspect()
61 {
62   if (myAspect.IsNull()) {
63     myAspect = new Graphic3d_AspectMarker3d(icon());
64   }
65 }
66
67 void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const
68 {
69   std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName);
70   if (aLine.get() == NULL)
71     return;
72   std::shared_ptr<GeomAPI_Edge> aEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLine));
73
74   std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
75   std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
76
77   Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1);
78   aLines->AddVertex(aPnt1->impl<gp_Pnt>());
79   aLines->AddVertex(aPnt2->impl<gp_Pnt>());
80   theGroup->AddPrimitiveArray(aLines);
81 }