0022819: Redesign of OpenGl driver
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_4.cxx
1 // File:      OpenGl_GraphicDriver_4.cxx
2 // Created:   20 October 2011
3 // Author:    Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
5
6 #include <OpenGl_GraphicDriver.hxx>
7
8 #include <NCollection_DataMap.hxx>
9 #include <OpenGl_Structure.hxx>
10 #include <OpenGl_CView.hxx>
11
12 void OpenGl_GraphicDriver::ClearStructure (const Graphic3d_CStructure& theCStructure)
13 {
14   OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
15   if (aStructure == NULL)
16     return;
17
18   aStructure->Clear();
19   InvalidateAllWorkspaces();
20 }
21
22 void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStructure)
23 {
24   OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
25   if (aStructure == NULL)
26     return;
27
28   aStructure->SetTransformPersistence (theCStructure.TransformPersistence);
29
30   if (theCStructure.ContextLine.IsDef)
31     aStructure->SetAspectLine (theCStructure.ContextLine);
32
33   if (theCStructure.ContextFillArea.IsDef)
34     aStructure->SetAspectFace (theCStructure.ContextFillArea);
35
36   if (theCStructure.ContextMarker.IsDef)
37     aStructure->SetAspectMarker (theCStructure.ContextMarker);
38
39   if (theCStructure.ContextText.IsDef)
40     aStructure->SetAspectText (theCStructure.ContextText);
41
42   InvalidateAllWorkspaces();
43 }
44
45 void OpenGl_GraphicDriver::Connect (const Graphic3d_CStructure& theFather,
46                                     const Graphic3d_CStructure& theSon)
47 {
48   OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
49   OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
50   if (aFather && aSon)
51     aFather->Connect(aSon);
52 }
53
54 void OpenGl_GraphicDriver::Disconnect (const Graphic3d_CStructure& theFather,
55                                        const Graphic3d_CStructure& theSon)
56 {
57   OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
58   OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
59   if (aFather && aSon)
60     aFather->Disconnect(aSon);
61 }
62
63 void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView&      theCView,
64                                              const Graphic3d_CStructure& theCStructure,
65                                              const Standard_Integer      thePriority)
66 {
67   const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
68   OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
69   if (aCView == NULL || aStructure == NULL)
70     return;
71
72   aCView->View->DisplayStructure (aStructure, thePriority);
73   aCView->WS->Invalidate();
74 }
75
76 void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView&      theCView,
77                                            const Graphic3d_CStructure& theCStructure)
78 {
79   const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
80   OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
81   if (aCView == NULL || aStructure == NULL)
82     return;
83
84   aCView->View->EraseStructure (aStructure);
85   aCView->WS->Invalidate();
86 }
87
88 void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure)
89 {
90   if (!GetMapOfStructures().IsBound (theCStructure.Id))
91     return;
92
93   OpenGl_Structure* aStructure = OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
94   OpenGl_GraphicDriver::GetMapOfStructures().UnBind (theCStructure.Id);
95   delete aStructure;
96   InvalidateAllWorkspaces();
97 }
98
99 void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure)
100 {
101   RemoveStructure (theCStructure);
102
103   OpenGl_Structure* aStructure = new OpenGl_Structure();
104
105   aStructure->SetDegenerateModel (theCStructure.ContextFillArea.DegenerationMode,
106                                   theCStructure.ContextFillArea.SkipRatio);
107
108   Standard_Integer aStatus = 0;
109   if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
110   if (!theCStructure.visible)  aStatus |= OPENGL_NS_HIDE;
111   if (theCStructure.pick)      aStatus |= OPENGL_NS_PICK;
112   aStructure->SetNamedStatus (aStatus);
113
114   theCStructure.ptrStructure = aStructure;
115   OpenGl_GraphicDriver::GetMapOfStructures().Bind (theCStructure.Id, aStructure);
116   InvalidateAllWorkspaces();
117 }