1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /***********************************************************************
22 Classe Visual3d_Layer :
24 HISTORIQUE DES MODIFICATIONS :
25 ----------------------------
26 Novembre 1998 : CAL : Creation.
29 ************************************************************************/
32 #include <Visual3d_Layer.ixx>
34 #include <Graphic3d_TypeOfPrimitive.hxx>
35 #include <Visual3d_ViewManager.hxx>
38 #define MyViewManager ((Visual3d_ViewManager *) MyPtrViewManager)
40 //-Global data definitions
41 static Standard_Boolean theLayerState = Standard_False;
42 static Graphic3d_TypeOfPrimitive theTypeOfPrimitive = Graphic3d_TOP_UNDEFINED;
51 Visual3d_Layer::Visual3d_Layer (const Handle(Visual3d_ViewManager)& AManager, const Aspect_TypeOfLayer ALayerType, const Standard_Boolean AFlag) {
53 cout << "Visual3d_Layer::Visual3d_Layer" << endl;
55 MyPtrViewManager = (void *) AManager.operator->();
57 MyGraphicDriver = MyViewManager->GraphicDriver();
59 MyCLayer.layerType = int (ALayerType);
60 MyCLayer.ptrLayer = NULL;
61 MyCLayer.ortho[0] = -1.0;
62 MyCLayer.ortho[1] = 1.0;
63 MyCLayer.ortho[2] = -1.0;
64 MyCLayer.ortho[3] = 1.0;
65 MyCLayer.attach = 0; // Aspect_TOC_BOTTOM_LEFT
66 MyCLayer.sizeDependent = (AFlag ? 1 : 0);
68 MyViewManager->SetLayer (this);
69 MyGraphicDriver->Layer (MyCLayer);
70 MyCLayer.ptrLayer->layerData = this;
73 cout << "Visual3d_Layer::Visual3d_Layer" << endl;
74 call_def_ptrLayer ptrLayer;
75 ptrLayer = (call_def_ptrLayer) MyCLayer.ptrLayer;
77 cout << "\tptrLayer == NULL" << endl;
79 cout << "\tptrLayer->listIndex = " << ptrLayer->listIndex << endl;
87 void Visual3d_Layer::Destroy () {
89 cout << "Visual3d_Layer::Destroy" << endl;
91 MyGraphicDriver->RemoveLayer (MyCLayer);
96 void Visual3d_Layer::Begin () {
98 cout << "Visual3d_Layer::Begin" << endl;
101 Visual3d_LayerDefinitionError::Raise
102 ("Layer is already open !");
104 MyGraphicDriver->BeginLayer (MyCLayer);
105 theLayerState = Standard_True;
108 void Visual3d_Layer::End () {
110 cout << "Visual3d_Layer::End" << endl;
113 cout << "Visual3d_Layer::End" << endl;
114 call_def_ptrLayer ptrLayer;
115 ptrLayer = (call_def_ptrLayer) MyCLayer.ptrLayer;
116 if (ptrLayer == NULL)
117 cout << "\tptrLayer == NULL" << endl;
119 cout << "\tptrLayer->listIndex = " << ptrLayer->listIndex << endl;
122 Visual3d_LayerDefinitionError::Raise
123 ("Layer is not open !");
125 // Flush all graphics
126 MyGraphicDriver->EndLayer ();
127 theLayerState = Standard_False;
129 cout << "Visual3d_Layer::End" << endl;
130 ptrLayer = (call_def_ptrLayer) MyCLayer.ptrLayer;
131 if (ptrLayer == NULL)
132 cout << "\tptrLayer == NULL" << endl;
134 cout << "\tptrLayer->listIndex = " << ptrLayer->listIndex << endl;
138 void Visual3d_Layer::Clear () {
140 cout << "Visual3d_Layer::Clear" << endl;
143 Visual3d_LayerDefinitionError::Raise
146 MyGraphicDriver->ClearLayer (MyCLayer);
150 //-Graphic definition methods
153 void Visual3d_Layer::BeginPolyline () {
155 cout << "Visual3d_Layer::BeginPolyline" << endl;
158 Visual3d_LayerDefinitionError::Raise
159 ("Layer is not open !");
160 if( theTypeOfPrimitive != Graphic3d_TOP_UNDEFINED )
161 Visual3d_LayerDefinitionError::Raise
162 ("One primitive is already open !");
164 theTypeOfPrimitive = Graphic3d_TOP_POLYLINE;
166 MyGraphicDriver->BeginPolyline2d ();
169 void Visual3d_Layer::BeginPolygon () {
171 cout << "Visual3d_Layer::BeginPolygon" << endl;
174 Visual3d_LayerDefinitionError::Raise
175 ("Layer is not open !");
176 if( theTypeOfPrimitive != Graphic3d_TOP_UNDEFINED )
177 Visual3d_LayerDefinitionError::Raise
178 ("One primitive is already open !");
180 theTypeOfPrimitive = Graphic3d_TOP_POLYGON;
182 MyGraphicDriver->BeginPolygon2d ();
185 void Visual3d_Layer::AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Boolean AFlag) {
187 cout << "Visual3d_Layer::AddVertex" << endl;
189 Standard_ShortReal x = Standard_ShortReal(X);
190 Standard_ShortReal y = Standard_ShortReal(Y);
192 switch (theTypeOfPrimitive) {
193 case Graphic3d_TOP_POLYLINE :
194 if( AFlag ) MyGraphicDriver->Draw (x, y);
195 else MyGraphicDriver->Move (x, y);
197 case Graphic3d_TOP_POLYGON :
198 MyGraphicDriver->Edge (x, y);
201 Visual3d_LayerDefinitionError::Raise
202 ("Bad Primitive type!");
206 void Visual3d_Layer::ClosePrimitive () {
208 cout << "Visual3d_Layer::ClosePrimitive" << endl;
210 switch (theTypeOfPrimitive) {
211 case Graphic3d_TOP_POLYLINE :
212 MyGraphicDriver->EndPolyline2d ();
214 case Graphic3d_TOP_POLYGON :
215 MyGraphicDriver->EndPolygon2d ();
218 Visual3d_LayerDefinitionError::Raise
219 ("Bad Primitive type!");
222 theTypeOfPrimitive = Graphic3d_TOP_UNDEFINED;
225 void Visual3d_Layer::DrawRectangle (const Standard_Real X, const Standard_Real Y, const Standard_Real Width, const Standard_Real Height) {
227 cout << "Visual3d_Layer::DrawRectangle" << endl;
230 Visual3d_LayerDefinitionError::Raise
231 ("Layer is not open !");
232 if (theTypeOfPrimitive != Graphic3d_TOP_UNDEFINED )
233 Visual3d_LayerDefinitionError::Raise
234 ("One primitive is already open !");
236 Standard_ShortReal x = Standard_ShortReal (X);
237 Standard_ShortReal y = Standard_ShortReal (Y);
238 Standard_ShortReal width = Standard_ShortReal (Width);
239 Standard_ShortReal height = Standard_ShortReal (Height);
240 MyGraphicDriver->Rectangle (x, y, width, height);
246 void Visual3d_Layer::DrawText (const Standard_CString AText, const Standard_Real X, const Standard_Real Y, const Standard_Real AHeight) {
248 cout << "Visual3d_Layer::DrawText" << endl;
251 Visual3d_LayerDefinitionError::Raise
252 ("Layer is not open !");
253 if (theTypeOfPrimitive != Graphic3d_TOP_UNDEFINED )
254 Visual3d_LayerDefinitionError::Raise
255 ("One primitive is already open !");
257 Standard_ShortReal x = Standard_ShortReal (X);
258 Standard_ShortReal y = Standard_ShortReal (Y);
259 Standard_ShortReal height = Standard_ShortReal (AHeight);
260 MyGraphicDriver->Text (AText, x, y, height);
263 void Visual3d_Layer::SetColor (const Quantity_Color& AColor) {
265 cout << "Visual3d_Layer::SetColor" << endl;
268 Visual3d_LayerDefinitionError::Raise
269 ("Layer is not open !");
271 Standard_ShortReal r = Standard_ShortReal (AColor.Red());
272 Standard_ShortReal g = Standard_ShortReal (AColor.Green());
273 Standard_ShortReal b = Standard_ShortReal (AColor.Blue());
275 cout << "\tSetColor : " << r << ", " << g << ", " << b << endl;
277 MyGraphicDriver->SetColor (r, g, b);
280 void Visual3d_Layer::SetTransparency (const Standard_ShortReal ATransparency) {
282 cout << "Visual3d_Layer::SetTransparency" << endl;
285 Visual3d_LayerDefinitionError::Raise
286 ("Layer is not open !");
289 cout << "\tSetTransparency : " << ATransparency << endl;
291 MyGraphicDriver->SetTransparency (ATransparency);
294 void Visual3d_Layer::UnsetTransparency () {
296 cout << "Visual3d_Layer::UnsetTransparency" << endl;
299 Visual3d_LayerDefinitionError::Raise
300 ("Layer is not open !");
303 cout << "\tUnsetTransparency" << endl;
305 MyGraphicDriver->UnsetTransparency ();
311 void Visual3d_Layer::TextSize (const Standard_CString AText, const Standard_Real AHeight, Standard_Real& AWidth, Standard_Real& AnAscent, Standard_Real& ADescent) const {
312 Standard_ShortReal aWidth, anAscent, aDescent;
315 cout << "Visual3d_Layer::TextSize" << endl;
318 Visual3d_LayerDefinitionError::Raise
319 ("Layer is not open !");
320 if (theTypeOfPrimitive != Graphic3d_TOP_UNDEFINED )
321 Visual3d_LayerDefinitionError::Raise
322 ("One primitive is already open !");
324 MyGraphicDriver->TextSize (AText, (Standard_ShortReal)AHeight, aWidth, anAscent, aDescent);
330 void Visual3d_Layer::SetLineAttributes (const Aspect_TypeOfLine AType, const Standard_Real AWidth) {
332 cout << "Visual3d_Layer::SetLineAttributes" << endl;
335 Visual3d_LayerDefinitionError::Raise
336 ("Layer is not open !");
338 Standard_Integer type = AType;
339 Standard_ShortReal width = Standard_ShortReal (AWidth);
341 cout << "\tSetLineAttributes : " << type << ", " << width << endl;
343 MyGraphicDriver->SetLineAttributes (type, width);
346 void Visual3d_Layer::SetTextAttributes (const Standard_CString AFont, const Aspect_TypeOfDisplayText AType, const Quantity_Color& AColor) {
348 cout << "Visual3d_Layer::SetTextAttributes" << endl;
351 Visual3d_LayerDefinitionError::Raise
352 ("Layer is not open !");
354 Standard_CString font = (char*)AFont;
355 Standard_Integer type = AType;
356 Standard_ShortReal r = Standard_ShortReal (AColor.Red());
357 Standard_ShortReal g = Standard_ShortReal (AColor.Green());
358 Standard_ShortReal b = Standard_ShortReal (AColor.Blue());
360 cout << "\tSetTextAttributes : " << font << ", " << type << endl;
361 cout << "\t " << r << ", " << g << ", " << b << endl;
363 MyGraphicDriver->SetTextAttributes (font, type, r, g, b);
366 void Visual3d_Layer::SetOrtho (const Standard_Real Left, const Standard_Real Right, const Standard_Real Bottom, const Standard_Real Top, const Aspect_TypeOfConstraint Attach) {
368 cout << "Visual3d_Layer::SetOrtho" << endl;
371 MyCLayer.ortho[0] = Standard_ShortReal (Left);
372 MyCLayer.ortho[1] = Standard_ShortReal (Right);
373 MyCLayer.ortho[2] = Standard_ShortReal (Bottom);
374 MyCLayer.ortho[3] = Standard_ShortReal (Top);
375 MyCLayer.attach = Standard_Integer (Attach);
378 void Visual3d_Layer::SetViewport (const Standard_Integer Width, const Standard_Integer Height) {
380 cout << "Visual3d_Layer::SetViewport" << endl;
383 MyCLayer.viewport[0] = float (Width);
384 MyCLayer.viewport[1] = float (Height);
387 Aspect_CLayer2d Visual3d_Layer::CLayer () const {
389 cout << "Visual3d_Layer::CLayer" << endl;
392 cout << "Visual3d_Layer::CLayer" << endl;
393 call_def_ptrLayer ptrLayer;
394 ptrLayer = (call_def_ptrLayer) MyCLayer.ptrLayer;
395 if (ptrLayer == NULL)
396 cout << "\tptrLayer == NULL" << endl;
398 cout << "\tptrLayer->listIndex = " << ptrLayer->listIndex << endl;
403 Aspect_TypeOfLayer Visual3d_Layer::Type () const {
405 cout << "Visual3d_Layer::Type" << endl;
407 return Aspect_TypeOfLayer (MyCLayer.layerType);
411 void Visual3d_Layer::AddLayerItem( const Handle(Visual3d_LayerItem&) Item )
413 MyListOfLayerItems.Append( Item );
416 void Visual3d_Layer::RemoveLayerItem( const Handle(Visual3d_LayerItem&) Item )
418 if ( MyListOfLayerItems.IsEmpty() )
421 Visual3d_NListOfLayerItem::Iterator it( MyListOfLayerItems );
422 for( ; it.More(); it.Next() ) {
423 if ( it.Value() == Item ) {
424 MyListOfLayerItems.Remove( it );
430 void Visual3d_Layer::RemoveAllLayerItems()
432 MyListOfLayerItems.Clear();
435 const Visual3d_NListOfLayerItem& Visual3d_Layer::GetLayerItemList() const
437 return MyListOfLayerItems;
440 void Visual3d_Layer::RenderLayerItems() const
442 theLayerState = Standard_True;
444 const Visual3d_NListOfLayerItem& items = GetLayerItemList();
445 Visual3d_NListOfLayerItem::Iterator it(items);
446 for(; it.More(); it.Next() ) {
447 it.Value()->RedrawLayerPrs();
450 theLayerState = Standard_False;