]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
fca01937933bf472db9c3b6a095ce0be0103b75d
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26
27 #include "GEOM_Displayer.h"
28
29 #include "GeometryGUI.h"
30
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
39
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_TopWireframeShape.hxx>
43 #include <GEOM_AISVector.hxx>
44 #include <GEOM_AISTrihedron.hxx>
45 #include <GEOM_VTKTrihedron.hxx>
46 #include <GEOM_VTKPropertyMaterial.hxx>
47
48 #include <Material_Model.h>
49
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ViewWindow.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_ResourceMgr.h>
55
56 #include <Basics_OCCTVersion.hxx>
57
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_Application.h>
60 #include <LightApp_SelectionMgr.h>
61 #include <LightApp_DataObject.h>
62 #include <SalomeApp_TypeFilter.h>
63 #include <SalomeApp_Tools.h>
64
65 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SALOME_ListIO.hxx>
67 #include <SALOME_Prs.h>
68
69 #include <SOCC_Prs.h>
70 #include <SOCC_ViewModel.h>
71
72 #include <SVTK_Prs.h>
73 #include <SVTK_ViewModel.h>
74
75 // OCCT Includes
76 #include <AIS_Drawer.hxx>
77 #include <AIS_ListIteratorOfListOfInteractive.hxx>
78 #include <Prs3d_IsoAspect.hxx>
79 #include <Prs3d_PointAspect.hxx>
80 #include <StdSelect_TypeOfEdge.hxx>
81 #include <StdSelect_TypeOfFace.hxx>
82 #include <StdSelect_DisplayMode.hxx>
83 #include <TopoDS_Face.hxx>
84 #include <BRep_Tool.hxx>
85 #include <Geom_Plane.hxx>
86 #include <Geom_Axis2Placement.hxx>
87 #include <Graphic3d_AspectFillArea3d.hxx>
88 #include <gp_Pln.hxx>
89 #include <TColStd_MapOfInteger.hxx>
90 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
91 #include <TopoDS_Iterator.hxx>
92 #include <Graphic3d_AspectMarker3d.hxx>
93 #include <TopTools_MapOfShape.hxx>
94 #include <TopTools_ListOfShape.hxx>
95 #include <TopTools_ListIteratorOfListOfShape.hxx>
96 #include <TopoDS.hxx>
97
98 #include <Prs3d_ShadingAspect.hxx>
99
100 #include <BRepMesh_IncrementalMesh.hxx>
101
102 // VTK Includes
103 #include <vtkActorCollection.h>
104 #include <vtkProperty.h>
105
106 // CORBA Headers
107 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
108
109 #include <GEOMImpl_Types.hxx>
110
111 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
112 #include <TColStd_HArray1OfByte.hxx>
113 #else
114 #include <Graphic3d_HArray1OfBytes.hxx>
115 #endif
116
117 // If the next macro is defined, autocolor feature works for all sub-shapes;
118 // if it is undefined, autocolor feature works for groups only
119 #define GENERAL_AUTOCOLOR
120 // Below macro, when uncommented, switches on simplified (more performant) algorithm
121 // of auto-color picking up
122 #define SIMPLE_AUTOCOLOR
123
124 // Hard-coded value of shape deflection coefficient for VTK viewer
125 const double VTK_MIN_DEFLECTION = 0.001;
126
127 //================================================================
128 // Function : getActiveStudy
129 // Purpose  : Get active study, returns 0 if no open study frame
130 //================================================================
131 static inline SalomeApp_Study* getActiveStudy()
132 {
133   SUIT_Session* session = SUIT_Session::session();
134   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
135   if ( app )
136     return ( SalomeApp_Study* )app->activeStudy();
137   return 0;
138 }
139
140 static inline int getViewManagerId( SALOME_View* theViewFrame) {
141   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
142   SUIT_ViewManager* aViewMgr = 0;
143   if (aModel != 0)
144     aViewMgr = aModel->getViewManager();
145   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
146 }
147
148 //================================================================
149 // Function : getTopAbsMode
150 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
151 //            one from GEOMImpl_Types.h
152 //================================================================
153 static inline int getTopAbsMode( const int implType )
154 {
155   switch ( implType )
156   {
157     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
158     case GEOM_SOLID     : return TopAbs_SOLID;
159     case GEOM_SHELL     : return TopAbs_SHELL;
160     case GEOM_FACE      : return TopAbs_FACE;
161     case GEOM_WIRE      : return TopAbs_WIRE;
162     case GEOM_EDGE      : return TopAbs_EDGE;
163     case GEOM_POINT     : return TopAbs_VERTEX;
164     default             : return -1;
165   }
166 }
167
168 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
169 {
170   if ( shape.IsNull() )
171     return TopAbs_SHAPE;
172
173   int ret = shape.ShapeType();
174
175   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
176     TopoDS_Iterator it(shape, Standard_True, Standard_False);
177     for (; it.More(); it.Next()) {
178       TopoDS_Shape sub_shape = it.Value();
179       if ( sub_shape.IsNull() ) continue;
180       int stype = getMinMaxShapeType( sub_shape, ismin );
181       if ( stype == TopAbs_SHAPE ) continue;
182       if ( ismin && stype > ret )
183         ret = stype;
184       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
185         ret = stype;
186     }
187   }
188
189   return ret;
190 }
191
192 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
193 {
194   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
195 }
196
197 //================================================================
198 // Function : getFilter
199 // Purpose  : Get filter corresponding to the type of object
200 //            from GEOMImpl_Types.h
201 //================================================================
202 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
203 {
204   SUIT_SelectionFilter* aFilter;
205
206   int aTopAbsMode = getTopAbsMode( theMode );
207   if ( aTopAbsMode != -1 )
208     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
209   else
210     switch ( theMode )
211       {
212       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
213       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
214
215       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
216       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
217       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
218       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
219       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
220       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
221
222       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
223
224       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
225       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
226
227       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
228       }
229
230   return aFilter;
231 }
232
233 //================================================================
234 // Function : getComplexFilter
235 // Purpose  : Get compound filter corresponding to the type of
236 //            object from GEOMImpl_Types.h
237 //================================================================
238 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
239 {
240   GEOM_CompoundFilter* aFilter;
241
242   if(aSubShapes != NULL ) {
243     aFilter = new GEOM_CompoundFilter(getStudy());
244     QList<int> aTopAbsTypes;
245     QList<int>::const_iterator it;
246     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
247       int topAbsMode = getTopAbsMode(*it);
248       if(topAbsMode != -1 )
249         aTopAbsTypes.append(topAbsMode);
250     }
251     aFilter->addSubTypes(aTopAbsTypes);
252   }
253
254   return aFilter;
255 }
256
257 //================================================================
258 // Function : getEntry
259 // Purpose  :
260 //================================================================
261 static std::string getEntry( GEOM::GEOM_Object_ptr object )
262 {
263   SUIT_Session* session = SUIT_Session::session();
264   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
265   if ( app )
266   {
267     CORBA::String_var IOR = app->orb()->object_to_string( object );
268     if ( strcmp(IOR.in(), "") != 0 )
269     {
270       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
271       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
272       if ( SO )
273         return SO->GetID();
274     }
275   }
276   return "";
277 }
278
279 //================================================================
280 // Function : getName
281 // Purpose  :
282 //================================================================
283 static std::string getName( GEOM::GEOM_Object_ptr object )
284 {
285   SUIT_Session* session = SUIT_Session::session();
286   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
287   if ( app )
288   {
289     CORBA::String_var IOR = app->orb()->object_to_string( object );
290     if ( strcmp(IOR.in(), "") != 0 )
291     {
292       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
293       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
294
295       _PTR(GenericAttribute) anAttr;
296
297       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
298       {
299         _PTR(AttributeName) aNameAttr( anAttr );
300         return aNameAttr->Value();
301       }
302     }
303   }
304
305   return "";
306 }
307
308 //=================================================================
309 /*!
310  *  GEOM_Displayer::GEOM_Displayer
311  *  Constructor
312  */
313 //=================================================================
314 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
315 {
316   if( st )
317     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
318   else
319     myApp = 0;
320
321   /* Shading Color */
322   SUIT_Session* session = SUIT_Session::session();
323   SUIT_ResourceMgr* resMgr = session->resourceMgr();
324
325   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
326   myShadingColor = SalomeApp_Tools::color( col );
327
328   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
329   myHasDisplayMode = false;
330
331   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
332   myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
333   myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
334
335   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
336   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
337   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
338
339   myColor = -1;
340   // This color is used for shape displaying. If it is equal -1 then
341   // default color is used.
342   myTexture = "";
343
344   myWidth = -1;
345   myType = -1;
346
347   myToActivate = true;
348   // This parameter is used for activisation/deactivisation of objects to be displayed
349
350   #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
351   // Activate parallel vizualisation only for testing purpose
352   // and if the corresponding env variable is set to 1
353   char* parallel_visu = getenv("PARALLEL_VISU");
354   if (parallel_visu && atoi(parallel_visu))
355   {
356     MESSAGE("Parallel visualisation on");
357     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
358   }
359   #endif
360
361   myViewFrame = 0;
362 }
363
364 //=================================================================
365 /*!
366  *  GEOM_Displayer::~GEOM_Displayer
367  *  Destructor
368  */
369 //=================================================================
370 GEOM_Displayer::~GEOM_Displayer()
371 {
372 }
373
374 //=================================================================
375 /*!
376  *  GEOM_Displayer::Display
377  *  Display interactive object in the current viewer
378  */
379 //=================================================================
380 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
381                              const bool updateViewer,
382                              SALOME_View* theViewFrame )
383 {
384   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
385   if ( vf )
386   {
387     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
388
389     if ( prs )
390     {
391       vf->BeforeDisplay( this, prs );
392       vf->Display( prs );
393       vf->AfterDisplay( this, prs );
394
395       if ( updateViewer )
396         vf->Repaint();
397
398       int aMgrId = getViewManagerId(vf);
399       SalomeApp_Study* aStudy = getStudy();
400       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
401
402       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
403
404       delete prs;  // delete presentation because displayer is its owner
405     }
406   }
407 }
408
409 //=================================================================
410 /*!
411  *  GEOM_Displayer::Display
412  *  This overloaded Display() method can be useful for operations
413  *  not using dialog boxes.
414  */
415 //=================================================================
416 void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer )
417 {
418   if ( theObj->_is_nil() )
419     return;
420
421   std::string entry = getEntry( theObj );
422   if ( entry != "" ) {
423     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
424             updateViewer);
425   }
426 }
427
428 //=================================================================
429 /*!
430  *  GEOM_Displayer::Erase
431  *  Erase interactive object in the current viewer
432  */
433 //=================================================================
434 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
435                             const bool forced,
436                             const bool updateViewer,
437                             SALOME_View* theViewFrame )
438 {
439   if ( theIO.IsNull() )
440     return;
441
442   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
443
444   if ( vf ) {
445     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
446     if ( prs ) {
447       vf->BeforeErase( this, prs );
448       vf->Erase( prs, forced );
449       vf->AfterErase( this, prs );
450       if ( updateViewer )
451         vf->Repaint();
452       delete prs;  // delete presentation because displayer is its owner
453
454       int aMgrId = getViewManagerId(vf);
455       SalomeApp_Study* aStudy = getStudy();
456       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
457
458       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
459     }
460   }
461 }
462
463 //=================================================================
464 /*!
465  *  GEOM_Displayer::Erase
466  *  Erase geometry object in the current viewer
467  */
468 //=================================================================
469 void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
470                             const bool forced,
471                             const bool updateViewer )
472 {
473   std::string entry = getEntry( theObj );
474   if ( entry != "" )
475   {
476     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
477           forced, updateViewer);
478   }
479 }
480
481 //=================================================================
482 /*!
483  *  GEOM_Displayer::Redisplay
484  *  Redisplay (erase and then display again) interactive object
485  *  in the current viewer
486  */
487 //=================================================================
488 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
489                                 const bool updateViewer )
490 {
491   // Remove the object permanently (<forced> == true)
492   SUIT_Session* ses = SUIT_Session::session();
493   SUIT_Application* app = ses->activeApplication();
494   if ( app )
495   {
496     SUIT_Desktop* desk = app->desktop();
497     QList<SUIT_ViewWindow*> wnds = desk->windows();
498     SUIT_ViewWindow* wnd;
499     QListIterator<SUIT_ViewWindow*> it( wnds );
500     while ( it.hasNext() && (wnd = it.next()) )
501     {
502       SUIT_ViewManager* vman = wnd->getViewManager();
503       if ( vman )
504       {
505         SUIT_ViewModel* vmodel = vman->getViewModel();
506         if ( vmodel )
507         {
508           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
509           if ( view )
510           {
511             if ( view->isVisible( theIO ) || view == GetActiveView() )
512             {
513               Erase( theIO, true, false, view );
514               Display( theIO, updateViewer, view );
515             }
516           }
517         }
518       }
519     }
520   }
521 }
522
523 //=================================================================
524 /*!
525  *  GEOM_Displayer::Display
526  *  Calls Display() method for each object in the given list
527  */
528 //=================================================================
529 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
530 {
531   SALOME_ListIteratorOfListIO Iter( theIOList );
532   for ( ; Iter.More(); Iter.Next() ) {
533     Display( Iter.Value(), false );
534   }
535   if ( updateViewer )
536     UpdateViewer();
537 }
538
539 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
540 {
541   // VSR: this method can be improved in future:
542   // to improve performance, the default values from resource manager should be cached in the displayer
543   return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
544 }
545
546 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
547 {
548   // VSR: this method can be improved in future:
549   // to improve performance, the default values from resource manager should be cached in the displayer
550   return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
551 }
552
553 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
554 {
555   // check that shape is not null
556   if ( AISShape.IsNull() ) return;
557   
558   // check that study is active
559   SalomeApp_Study* study = getStudy();
560   if ( !study ) return;
561
562   if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
563        !TopoDS_Iterator(myShape).More() )
564     return; // NPAL15983 (Bug when displaying empty groups)
565
566   // set interactive object
567
568   Handle( SALOME_InteractiveObject ) anIO;
569
570   if ( !myIO.IsNull() ) {
571     AISShape->setIO( myIO );
572     AISShape->SetOwner( myIO );
573     anIO = myIO;
574   }
575   else if ( !myName.empty() ) {
576     // workaround to allow selection of temporary objects
577     static int tempId = 0;
578     anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
579     AISShape->setIO( anIO );
580     AISShape->SetOwner( anIO );
581   }
582
583   // flag:  only vertex or compound of vertices is processed (specific handling)
584   bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
585   // presentation study entry (empty for temporary objects like preview)
586   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
587   // flag: temporary object
588   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
589   // currently active view window's ID (-1 if no active view)
590   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
591
592   // get presentation properties
593   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
594
595   // Temporary staff: vertex must be infinite for correct visualization
596   AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
597
598   // set material
599   Material_Model material;
600   // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
601   if( !HasColor() )
602     material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
603   // - set front material properties
604   AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
605   AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
606   // - set back material properties
607   AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
608   AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
609   // - switch to default (both sides) facing mode
610   AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
611
612   // set colors
613
614   // - shading color
615   if ( HasColor()  ) {
616     // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
617     // we set it to the shape not taking into account material properties
618     AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
619   }
620   else if ( !material.isPhysical() ) {
621     // shading color from properties is used only for non-physical materials
622     AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
623   }
624
625   // - wireframe color
626   Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
627   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
628                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
629   AISShape->Attributes()->SetLineAspect( anAspect );
630   
631   // - unfree boundaries color
632   anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
633   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
634                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
635   AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
636   
637   // - free boundaries color
638   anAspect = AISShape->Attributes()->FreeBoundaryAspect();
639   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
640                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
641   AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
642   
643   // - standalone edges color
644   anAspect = AISShape->Attributes()->WireAspect();
645   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
646                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
647   AISShape->Attributes()->SetWireAspect( anAspect );
648   
649   // - color for edges in shading+edges mode
650   AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
651   
652   // ???
653   AISShape->storeBoundaryColors();
654
655   // set display mode
656   AISShape->SetDisplayMode( HasDisplayMode() ? 
657                             // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
658                             GetDisplayMode() :
659                             // display mode from properties
660                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
661
662   // set display vectors flag
663   AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
664
665   // set transparency
666   // VSR: ??? next line is commented: transparency property is set in the AfterDisplay() function
667   //AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
668
669   // set iso properties
670   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
671   int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
672   Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
673   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
674   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
675   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
676   uIsoAspect->SetColor( isosColor );
677   uIsoAspect->SetWidth( isosWidth );
678   uIsoAspect->SetNumber( uIsos );
679   vIsoAspect->SetColor( isosColor );
680   vIsoAspect->SetWidth( isosWidth );
681   vIsoAspect->SetNumber( vIsos );
682   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
683   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
684
685   // set deflection coefficient
686   // ... to avoid to small values of the coefficient, its lower value is limited 
687   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
688
689   // set texture
690   if ( HasTexture() ) {
691     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
692     AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
693     AISShape->SetTextureMapOn();
694     AISShape->DisableTextureModulate();
695     AISShape->SetDisplayMode( 3 );
696   }
697
698   // set line width
699   AISShape->SetWidth( HasWidth() ?
700                       // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
701                       GetWidth() :
702                       // libe width from properties
703                       propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
704
705   // set top-level flag
706   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
707
708   // set point marker (for vertex / compound of vertices only)
709   if ( onlyVertex ) {
710     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
711     if ( aList.size() == 2 ) {
712       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
713       int aTypeOfMarker = aList[0].toInt();
714       double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
715       Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
716       anAspect->SetScale( aScaleOfMarker );
717       anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
718       anAspect->SetColor( HasColor() ? 
719                           // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
720                           (Quantity_NameOfColor)GetColor() : 
721                           // color from properties
722                           SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
723       AISShape->Attributes()->SetPointAspect( anAspect );
724     }
725     else if ( aList.size() == 1 ) {
726       // custom marker string contains "IdOfTexture"
727       int textureId = aList[0].toInt();
728       Standard_Integer aWidth, aHeight;
729 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
730       Handle(TColStd_HArray1OfByte) aTexture =
731 #else
732         Handle(Graphic3d_HArray1OfBytes) aTexture =
733 #endif
734         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
735       if ( !aTexture.IsNull() ) {
736 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
737         Handle(Prs3d_PointAspect) aTextureAspect =
738           new Prs3d_PointAspect( HasColor() ? 
739                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
740                                  (Quantity_NameOfColor)GetColor() : 
741                                  // color from properties 
742                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
743                                  aWidth, aHeight,
744                                  aTexture );
745 #else
746         int TextureId = 0;
747         Handle(Prs3d_PointAspect) aTextureAspect =
748           new Prs3d_PointAspect( HasColor() ? 
749                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
750                                  (Quantity_NameOfColor)GetColor() : 
751                                  // color from properties 
752                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ), 
753                                  ++TextureId,
754                                  aWidth, aHeight,
755                                  aTexture );
756 #endif
757         AISShape->Attributes()->SetPointAspect( aTextureAspect );
758       }
759     }
760   }
761
762   if ( create && !isTemporary && aMgrId != -1 ) {
763     // set properties to the study
764     study->setObjectPropMap( aMgrId, entry, propMap );
765   }
766
767   // AISShape->SetName(???); ??? necessary to set name ???
768 }
769
770 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
771 {
772   // check that actor is not null
773   if ( !actor ) return;
774   
775   // check that study is active
776   SalomeApp_Study* study = getStudy();
777   if ( !study ) return;
778
779   // set interactive object
780
781   Handle( SALOME_InteractiveObject ) anIO;
782
783   if ( !myIO.IsNull() ) {
784     actor->setIO( myIO );
785     anIO = myIO;
786   }
787   else if ( !myName.empty() ) {
788     // workaround to allow selection of temporary objects
789     static int tempId = 0;
790     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
791     actor->setIO( anIO );
792   }
793
794   // presentation study entry (empty for temporary objects like preview)
795   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
796   // flag: temporary object
797   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
798   // currently active view window's ID (-1 if no active view)
799   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
800
801   // get presentation properties
802   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
803   QColor c;
804
805   /////////////////////////////////////////////////////////////////////////
806   // VSR: for VTK viewer currently deflection coefficient is hardcoded
807   //      due to performance problem
808   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
809   /////////////////////////////////////////////////////////////////////////
810   if ( !actor->getTopo().IsSame( myShape ) )
811     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
812
813   // set material
814   Material_Model material;
815   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
816   std::vector<vtkProperty*> mprops;
817   mprops.push_back( material.getMaterialVTKProperty( true ) );
818   mprops.push_back( material.getMaterialVTKProperty( false) );
819   actor->SetMaterial( mprops );
820
821   // set iso-lines properties
822
823   // - set number of iso-lines
824   int nbIsos[2]= { 1, 1 };
825   QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
826   nbIsos[0] = isos[0].toInt();
827   nbIsos[1] = isos[1].toInt();
828   actor->SetNbIsos( nbIsos );
829
830   // - set iso-lines width
831   actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
832
833   // - set iso-lines color
834   c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
835   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
836
837   // set colors
838
839   if ( HasColor()  ) {
840     // - same color for all sub-actors
841     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
842     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
843   }
844   else {
845     // shading color (for non-physical materials)
846     if ( !material.isPhysical() ) {
847       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
848       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
849       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
850     }
851
852     // - standalone edge color
853     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
854     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
855
856     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
857     // - shared edges color ???
858     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
859
860     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
861     // - free edges color ???
862     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
863
864     // - point color
865     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
866     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
867   }
868
869   // - color for edges in shading+edges mode
870   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
871   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
872
873   // set opacity
874   actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
875
876   // set line width
877   actor->SetWidth( HasWidth() ?
878                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
879                    GetWidth() :
880                    // libe width from properties
881                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
882   
883   // set display vectors flag
884   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
885
886   // set display mode
887   int displayMode = HasDisplayMode() ? 
888     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
889     GetDisplayMode() :
890     // display mode from properties
891     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
892
893   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
894   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
895   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
896   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
897
898   if ( displayMode == 2 )
899       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
900       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
901     displayMode++;
902   actor->setDisplayMode( displayMode );
903
904   if ( myToActivate )
905     actor->PickableOn();
906   else
907     actor->PickableOff();
908
909   if ( create && !isTemporary && aMgrId != -1 ) {
910     // set properties to the study
911     study->setObjectPropMap( aMgrId, entry, propMap );
912   }
913 }
914
915 //=================================================================
916 /*!
917  *  GEOM_Displayer::Erase
918  *  Calls Erase() method for each object in the given list
919  */
920 //=================================================================
921 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
922                             const bool forced,
923                             const bool updateViewer )
924 {
925   SALOME_ListIteratorOfListIO Iter( theIOList );
926   for ( ; Iter.More(); Iter.Next() )
927     Erase( Iter.Value(), forced, false );
928
929   if ( updateViewer )
930     UpdateViewer();
931 }
932
933 //=================================================================
934 /*!
935  *  GEOM_Displayer::Redisplay
936  *  Calls Redisplay() method for each object in the given list
937  */
938 //=================================================================
939 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
940 {
941   SALOME_ListIteratorOfListIO Iter( theIOList );
942   for ( ; Iter.More(); Iter.Next() )
943     Redisplay( Iter.Value(), false );
944
945   if ( updateViewer )
946     UpdateViewer();
947 }
948
949 //=================================================================
950 /*!
951  *  GEOM_Displayer::Update
952  *  Update OCC presentaion
953  *  [ Reimplemented from SALOME_Displayer ]
954  */
955 //=================================================================
956 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
957 {
958   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
959   SalomeApp_Study* study = getStudy();
960
961   if ( !occPrs || myShape.IsNull() || !study )
962     return;
963
964   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
965   {
966     // 
967     // specific processing for local coordinate system presentation
968     // 
969
970     TopoDS_Face aFace = TopoDS::Face( myShape );
971     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
972     if ( !aPlane.IsNull() )
973     {
974       gp_Ax3 aPos = aPlane->Pln().Position();
975       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
976
977       Handle(GEOM_AISTrihedron) aTrh;
978
979       if ( occPrs->IsNull() )
980       {
981         // new presentation is being created
982         aTrh = new GEOM_AISTrihedron( aPlc );
983         occPrs->AddObject( aTrh );
984       }
985       else
986       {
987         // presentation is being updated
988         AIS_ListOfInteractive aList;
989         occPrs->GetObjects( aList );
990         AIS_ListIteratorOfListOfInteractive anIter( aList );
991         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
992           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
993         }
994       }
995         
996       if ( !aTrh.IsNull() ) {
997         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
998         if ( HasColor() )
999           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1000         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1001         if ( HasWidth() )
1002           aTrh->SetWidth( GetWidth() );
1003         
1004         if ( !myIO.IsNull() )
1005         {
1006           aTrh->setIO( myIO );
1007           aTrh->SetOwner( myIO );
1008         }
1009         aTrh->SetComponent( aPlc );
1010         aTrh->SetToUpdate();
1011       }
1012       occPrs->SetToActivate( ToActivate() );
1013     }
1014   }
1015   else
1016   {
1017     // 
1018     // processing for usual geometry presentation
1019     // 
1020
1021     // if presentation is empty we try to create new one
1022     if ( occPrs->IsNull() )
1023     {
1024       // create presentation (specific for vectors)
1025       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1026                                                                  : new GEOM_AISShape ( myShape, "" );
1027       // update shape properties
1028       updateShapeProperties( AISShape, true );
1029
1030       // add shape to the presentation
1031       occPrs->AddObject( AISShape );
1032
1033       // In accordance with ToActivate() value object will be activated/deactivated
1034       // when it will be displayed
1035       occPrs->SetToActivate( ToActivate() );
1036
1037       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1038         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1039
1040         // create additional wireframe shape
1041         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1042         aWirePrs->SetWidth(AISShape->Width());
1043         if ( !myIO.IsNull() ) {
1044           aWirePrs->setIO( myIO );
1045           aWirePrs->SetOwner( myIO );
1046         }
1047
1048         // add shape to the presentation
1049         occPrs->AddObject( aWirePrs );
1050       }
1051     }
1052     // if presentation is found -> set again shape for it
1053     else
1054     {
1055       AIS_ListOfInteractive IOList;
1056       occPrs->GetObjects( IOList );
1057       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1058       for ( ; Iter.More(); Iter.Next() )
1059       {
1060         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1061         if ( AISShape.IsNull() )
1062           continue;
1063
1064         // re-set shape (it might be changed)
1065         if ( AISShape->Shape() != myShape )
1066           AISShape->Set( myShape );
1067
1068         // update shape properties
1069         updateShapeProperties( AISShape, false );
1070
1071         // force updating
1072         AISShape->UpdateSelection();
1073         AISShape->SetToUpdate();
1074       }
1075     }
1076   }
1077 }
1078
1079 //=================================================================
1080 /*!
1081  *  GEOM_Displayer::Update
1082  *  Update VTK presentaion
1083  *  [ Reimplemented from SALOME_Displayer ]
1084  */
1085 //=================================================================
1086 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1087 {
1088   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1089   SalomeApp_Study* study = getStudy();
1090
1091   if ( !vtkPrs || myShape.IsNull() || !study )
1092     return;
1093
1094   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1095   {
1096     // 
1097     // specific processing for local coordinate system presentation
1098     // 
1099
1100     TopoDS_Face aFace = TopoDS::Face( myShape );
1101     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1102     if ( !aPlane.IsNull() ) {
1103       gp_Ax3 aPos = aPlane->Pln().Position();
1104       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1105
1106       GEOM_VTKTrihedron* aTrh = 0;
1107
1108       if ( vtkPrs->IsNull() ) {
1109         // new presentation is being created
1110         aTrh = GEOM_VTKTrihedron::New();
1111         vtkPrs->AddObject( aTrh );
1112       }
1113       else {
1114         // presentation is being updated
1115         vtkActorCollection* actors = vtkPrs->GetObjects();
1116         if ( actors ) {
1117           actors->InitTraversal();
1118           vtkActor* a = actors->GetNextActor();
1119           while ( a && !aTrh ) {
1120             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1121             a = actors->GetNextActor();
1122           }
1123         }
1124       }
1125       
1126       if ( aTrh ) {
1127         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1128         if ( HasColor() ) {
1129           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1130           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1131         }
1132 #ifdef VTK_TRIHEDRON_WIDTH
1133         // 
1134         // VSR: currently isn't supported
1135         //
1136         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1137         if ( HasWidth() )
1138           aTrh->SetWidth( GetWidth() );
1139 #endif
1140
1141         if ( !myIO.IsNull() )
1142           aTrh->setIO( myIO );
1143
1144         aTrh->SetPlacement( aPlc );
1145       }
1146     }
1147   }
1148   else
1149   {
1150     // 
1151     // processing for usual geometry presentation
1152     // 
1153
1154     // if presentation is empty we try to create new one
1155     if ( vtkPrs->IsNull() )
1156     {
1157       // create an actor
1158       GEOM_Actor* actor = GEOM_Actor::New();
1159       // update actor properties
1160       updateActorProperties( actor, true );
1161       // add actor to the presentation
1162       vtkPrs->AddObject( actor );
1163     }
1164     else {
1165       // presentation is being updated
1166       vtkActorCollection* actors = vtkPrs->GetObjects();
1167       if ( actors ) {
1168         actors->InitTraversal();
1169         vtkActor* a = actors->GetNextActor();
1170         while ( a ) {
1171           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1172           if ( actor ) {
1173             // update actor properties
1174             updateActorProperties( actor, false );
1175             a = actors->GetNextActor();
1176           }
1177         }
1178       }
1179     }
1180   }
1181 }
1182
1183 //=================================================================
1184 /*!
1185  *  GEOM_Displayer::BuildPrs
1186  *  Build presentation accordint to the current viewer type
1187  */
1188 //=================================================================
1189 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1190 {
1191   if ( theObj->_is_nil() )
1192     return 0;
1193
1194   myViewFrame = GetActiveView();
1195   if ( myViewFrame == 0 )
1196     return 0;
1197
1198   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1199   if ( aPrs == 0 )
1200     return 0;
1201
1202   internalReset();
1203   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1204   myType = theObj->GetType();
1205
1206   // Update presentation
1207   UpdatePrs( aPrs );
1208
1209   return aPrs;
1210 }
1211
1212 //=================================================================
1213 /*!
1214  *  GEOM_Displayer::BuildPrs
1215  *  Build presentation accordint to the current viewer type
1216  */
1217 //=================================================================
1218 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1219 {
1220   myViewFrame = GetActiveView();
1221   if ( theShape.IsNull() || myViewFrame == 0 )
1222     return 0;
1223
1224   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1225   if ( aPrs == 0 )
1226     return 0;
1227
1228   internalReset();
1229   setShape( theShape );
1230   myType = -1;
1231
1232   UpdatePrs( aPrs );
1233
1234   return aPrs;
1235 }
1236
1237 //=================================================================
1238 /*!
1239  *  GEOM_Displayer::buildPresentation
1240  *  Builds/finds object's presentation for the current viewer
1241  *  Calls corresponding Update() method by means of double dispatch
1242  *  [ internal ]
1243  */
1244 //=================================================================
1245 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1246                                                SALOME_View* theViewFrame )
1247 {
1248   SALOME_Prs* prs = 0;
1249   internalReset();
1250
1251   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1252
1253   if ( myViewFrame )
1254   {
1255     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1256     if ( prs )
1257     {
1258       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1259       theIO->setEntry( entry.toLatin1().constData() );
1260       if ( !theIO.IsNull() )
1261       {
1262         // set interactive object
1263         setIO( theIO );
1264         //  Find SOBject (because shape should be published previously)
1265         SUIT_Session* session = SUIT_Session::session();
1266         SUIT_Application* app = session->activeApplication();
1267         if ( app )
1268         {
1269           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1270           if ( study )
1271           {
1272             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1273             if ( SO )
1274             {
1275               // get CORBA reference to data object
1276               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1277               if ( !CORBA::is_nil( object ) )
1278               {
1279                 // downcast to GEOM object
1280                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1281                 if ( !GeomObject->_is_nil() )
1282                 {
1283                   // finally set shape
1284                   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1285                   myType = GeomObject->GetType();
1286                 }
1287               }
1288             }
1289           }
1290         }
1291       }
1292       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1293     }
1294   }
1295   return prs;
1296 }
1297
1298 //=================================================================
1299 /*!
1300  *  GEOM_Displayer::buildSubshapePresentation
1301  *  Builds/finds object's presentation for the current viewer
1302  *  Calls corresponding Update() method by means of double dispatch
1303  *  For not published objects (for Mantis issue 0020435)
1304  */
1305 //=================================================================
1306 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1307                                                       const QString& entry,
1308                                                       SALOME_View* theViewFrame)
1309 {
1310   SALOME_Prs* prs = 0;
1311   internalReset();
1312
1313   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1314
1315   if (myViewFrame)
1316   {
1317     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1318     if (prs)
1319     {
1320       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1321       theIO->setEntry(entry.toLatin1().constData());
1322       if (!theIO.IsNull())
1323       {
1324         // set interactive object
1325         setIO(theIO);
1326         // finally set shape
1327         setShape(aShape);
1328         myType = GEOM_SUBSHAPE;
1329       }
1330       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1331     }
1332   }
1333   return prs;
1334 }
1335
1336 //=================================================================
1337 /*!
1338  *  GEOM_Displayer::internalReset
1339  *  Resets internal data
1340  *  [internal]
1341  */
1342 //=================================================================
1343 void GEOM_Displayer::internalReset()
1344 {
1345   myIO.Nullify();
1346   myShape.Nullify();
1347 }
1348
1349 //=================================================================
1350 /*!
1351  *  GEOM_Displayer::LocalSelection
1352  *  Activate selection of CAD shapes with activisation of selection
1353  *  of their sub-shapes (with opened local context for OCC viewer)
1354  */
1355 //=================================================================
1356 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1357 {
1358   SUIT_Session* session = SUIT_Session::session();
1359   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1360   if ( !app )
1361     return;
1362
1363   LightApp_SelectionMgr* sm = app->selectionMgr();
1364
1365   // remove all filters from selection
1366   sm->clearFilters();
1367
1368   SALOME_View* vf = GetActiveView();
1369   if ( vf ) {
1370     if (!theIO.IsNull() && !vf->isVisible(theIO))
1371       Display(theIO);
1372     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1373     vf->LocalSelection( prs, theMode );
1374     delete prs;  // delete presentation because displayer is its owner
1375   }
1376 }
1377
1378 //=================================================================
1379 /*!
1380  *  GEOM_Displayer::globalSelection
1381  *  Activate selection of CAD shapes without activisation of selection
1382  *  of their sub-shapes (without opened local context for OCC viewer)
1383  */
1384 //=================================================================
1385 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1386 {
1387   TColStd_MapOfInteger aModes;
1388   aModes.Add( theMode );
1389   GlobalSelection( aModes, update );
1390 }
1391
1392 //=================================================================
1393 /*!
1394  *  GEOM_Displayer::globalSelection
1395  *  Activate selection of CAD shapes without activisation of selection
1396  *  of their sub-shapes (without opened local context for OCC viewer)
1397  */
1398 //=================================================================
1399 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1400                                       const bool update, const QList<int>* theSubShapes )
1401 {
1402   SUIT_Session* session = SUIT_Session::session();
1403   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1404   if ( !app )
1405     return;
1406
1407   SALOME_View* vf = GetActiveView();
1408   if ( vf == 0 )
1409     return;
1410
1411   // Close local context
1412   vf->GlobalSelection( update );
1413
1414   // Set selection filters in accordance with current mode
1415   LightApp_SelectionMgr* sm = app->selectionMgr();
1416   if ( !sm )
1417     return;
1418
1419   // Remove from selection temporary objects if necessary
1420   if ( !theModes.Contains( GEOM_PREVIEW ) )
1421     clearTemporary( sm );
1422
1423   //@ aSel->ClearIndex();
1424
1425   sm->clearFilters();
1426
1427   // Remove filters from AIS_InteractiveContext
1428   Handle(AIS_InteractiveContext) ic;
1429   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1430   if ( viewer )
1431     {
1432       ic = viewer->getAISContext();
1433       if ( !ic.IsNull() )
1434         ic->RemoveFilters();
1435     }
1436
1437   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1438     return;
1439
1440   SUIT_SelectionFilter* aFilter;
1441   if ( theModes.Extent() == 1 )
1442     {
1443       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1444
1445       if ( aMode == GEOM_COMPOUNDFILTER )
1446         aFilter = getComplexFilter( theSubShapes );
1447       else
1448         aFilter = getFilter( aMode );
1449     }
1450   else if ( theModes.Extent() > 1 )
1451     {
1452       TColStd_MapOfInteger aTopAbsModes;
1453       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1454       QList<SUIT_SelectionFilter*> aListOfFilters;
1455       for ( ; anIter.More(); anIter.Next() )
1456         {
1457           SUIT_SelectionFilter* aFilter;
1458           int aMode = anIter.Key();
1459           if ( aMode == GEOM_COMPOUNDFILTER )
1460             aFilter = getComplexFilter( theSubShapes );
1461           else
1462             aFilter = getFilter( aMode );
1463
1464           if ( aFilter )
1465             aListOfFilters.append( aFilter );
1466         }
1467
1468       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1469     }
1470   else
1471     return;
1472
1473   if ( aFilter )
1474     {
1475       sm->installFilter( aFilter );
1476       if ( !ic.IsNull() )
1477         {
1478           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1479           ic->AddFilter( anOCCFilter );
1480         }
1481     }
1482 }
1483
1484 //=================================================================
1485 /*!
1486  *  GEOM_Displayer::LocalSelection
1487  *  Activate selection of CAD shapes with activisation of selection
1488  *  of their sub-shapes (with opened local context for OCC viewer)
1489  */
1490 //=================================================================
1491 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1492 {
1493   SALOME_ListIteratorOfListIO Iter( theIOList );
1494   for ( ; Iter.More(); Iter.Next() )
1495     LocalSelection( Iter.Value(), theMode );
1496 }
1497
1498 //=================================================================
1499 /*!
1500  *  GEOM_Displayer::BeforeDisplay
1501  *  Called before displaying of pars. Close local context
1502  *  [ Reimplemented from SALOME_Displayer ]
1503  */
1504 //=================================================================
1505 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1506 {
1507   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1508   if ( vf )
1509   {
1510     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1511     if ( !ic.IsNull() )
1512     {
1513       if ( ic->HasOpenedContext() )
1514       ic->CloseAllContexts();
1515     }
1516   }
1517 }
1518
1519 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1520 {
1521   SalomeApp_Study* aStudy = getStudy();
1522   if (!aStudy) return;
1523   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1524   if ( vf && !p->IsNull() ) {
1525     int aMgrId = getViewManagerId( vf );
1526     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1527     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1528     if ( !ic.IsNull() && prs ) {
1529       AIS_ListOfInteractive objects;
1530       prs->GetObjects( objects );
1531       AIS_ListIteratorOfListOfInteractive it( objects );
1532       for ( ; it.More(); it.Next() ) {
1533         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1534         if ( sh.IsNull() ) continue;
1535         Handle(SALOME_InteractiveObject) IO = sh->getIO();
1536         if ( IO.IsNull() ) continue;
1537         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1538         if ( aPropMap.contains( GEOM::propertyName( GEOM::Transparency ) ) ) {
1539           double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble();
1540           ic->SetTransparency( sh, transparency, true );
1541         }
1542       }
1543     }
1544   }
1545 }
1546
1547 //=================================================================
1548 /*!
1549  *  GEOM_Displayer::SetColor
1550  *  Set color for shape displaying. If it is equal -1 then default color is used.
1551  *  Available values are from Quantity_NameOfColor enumeration
1552  */
1553 //=================================================================
1554 void GEOM_Displayer::SetColor( const int color )
1555 {
1556   if ( color == -1 )
1557     UnsetColor();
1558   else
1559   {
1560     myColor = color;
1561     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1562   }
1563 }
1564
1565 int GEOM_Displayer::GetColor() const
1566 {
1567   return myColor;
1568 }
1569
1570 bool GEOM_Displayer::HasColor() const
1571 {
1572   return myColor != -1;
1573 }
1574
1575 void GEOM_Displayer::UnsetColor()
1576 {
1577   myColor = -1;
1578
1579   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1580   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1581   myShadingColor = SalomeApp_Tools::color( col );
1582 }
1583
1584 //=================================================================
1585 /*!
1586  *  GEOM_Displayer::SetTexture
1587  *  Set color for shape displaying. If it is equal -1 then default color is used.
1588  *  Available values are from Quantity_NameOfColor enumeration
1589  */
1590 //=================================================================
1591 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1592 {
1593   if(texureFileName!="")
1594   {
1595     myTexture = texureFileName;
1596   }
1597 }
1598
1599 bool GEOM_Displayer::HasTexture() const
1600 {
1601   return myTexture != "";
1602 }
1603
1604 std::string GEOM_Displayer::GetTexture() const
1605 {
1606   return myTexture;
1607 }
1608
1609 //=================================================================
1610 /*!
1611  *  GEOM_Displayer::SetWidth
1612  *  Set width of shape displaying. If it is equal -1 then default width is used.
1613  */
1614 //=================================================================
1615 void GEOM_Displayer::SetWidth( const double width )
1616 {
1617   myWidth = width;
1618 }
1619
1620 double GEOM_Displayer::GetWidth() const
1621 {
1622   return myWidth;
1623 }
1624
1625 bool GEOM_Displayer::HasWidth() const
1626 {
1627   return myWidth != -1;
1628 }
1629
1630 void GEOM_Displayer::UnsetWidth()
1631 {
1632   myWidth = -1;
1633 }
1634
1635
1636 int GEOM_Displayer::GetIsosWidth() const
1637 {
1638   return myIsosWidth;
1639 }
1640
1641 void GEOM_Displayer::SetIsosWidth(const int width)
1642 {
1643   myIsosWidth = width;
1644 }
1645
1646 bool GEOM_Displayer::HasIsosWidth() const
1647 {
1648   return myIsosWidth != -1;
1649 }
1650
1651
1652 //=================================================================
1653 /*!
1654  *  GEOM_Displayer::SetToActivate
1655  *  This method is used for activisation/deactivisation of objects to be displayed
1656  */
1657 //=================================================================
1658 void GEOM_Displayer::SetToActivate( const bool toActivate )
1659 {
1660   myToActivate = toActivate;
1661 }
1662 bool GEOM_Displayer::ToActivate() const
1663 {
1664   return myToActivate;
1665 }
1666
1667 //=================================================================
1668 /*!
1669  *  GEOM_Displayer::clearTemporary
1670  *  Removes from selection temporary objects
1671  */
1672 //=================================================================
1673 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1674 {
1675   SALOME_ListIO selected, toSelect;
1676   theSelMgr->selectedObjects( selected );
1677
1678   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1679     Handle(SALOME_InteractiveObject) io = it.Value();
1680     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1681       toSelect.Append( it.Value() );
1682   }
1683
1684   theSelMgr->setSelectedObjects( toSelect, true );
1685 }
1686
1687 void GEOM_Displayer::SetName( const char* theName )
1688 {
1689   myName = theName;
1690 }
1691
1692 void GEOM_Displayer::UnsetName()
1693 {
1694   myName = "";
1695 }
1696
1697 SalomeApp_Study* GEOM_Displayer::getStudy() const
1698 {
1699   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1700 }
1701
1702 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1703 {
1704   myIO = theIO;
1705 }
1706
1707 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1708 {
1709   myShape = theShape;
1710 }
1711
1712 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1713 {
1714   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
1715   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
1716   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
1717   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aCompObj ) ) && (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
1718 }
1719
1720 int GEOM_Displayer::SetDisplayMode( const int theMode )
1721 {
1722   int aPrevMode = myDisplayMode;
1723   if ( theMode != -1 ) {
1724     myDisplayMode = theMode;
1725     myHasDisplayMode = true;
1726   }
1727   else {
1728     UnsetDisplayMode();
1729   }
1730   return aPrevMode;
1731 }
1732
1733 int GEOM_Displayer::GetDisplayMode() const
1734 {
1735   return myDisplayMode;
1736 }
1737
1738 int GEOM_Displayer::UnsetDisplayMode()
1739 {
1740   int aPrevMode = myDisplayMode;
1741   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1742   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1743   myHasDisplayMode = false;
1744   return aPrevMode;
1745 }
1746
1747 bool GEOM_Displayer::HasDisplayMode() const
1748 {
1749   return myHasDisplayMode;
1750 }
1751
1752 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1753 {
1754   static QList<QColor> colors;
1755
1756   if ( colors.isEmpty() ) {
1757
1758     for (int s = 0; s < 2 ; s++)
1759     {
1760       for (int v = 100; v >= 40; v = v - 20)
1761       {
1762         for (int h = 0; h < 359 ; h = h + 60)
1763         {
1764           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1765         }
1766       }
1767     }
1768   }
1769
1770   static int currentColor = 0;
1771
1772   SALOMEDS::Color color;
1773   color.R = (double)colors[currentColor].red()   / 255.0;
1774   color.G = (double)colors[currentColor].green() / 255.0;
1775   color.B = (double)colors[currentColor].blue()  / 255.0;
1776
1777   currentColor = (currentColor+1) % colors.count();
1778
1779   return color;
1780 }
1781
1782 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1783 {
1784   int aHue = -1;
1785   int aTolerance = 64;
1786   int anIterations = 0;
1787   int aPeriod = 5;
1788
1789   while( 1 )
1790   {
1791     anIterations++;
1792     if( anIterations % aPeriod == 0 )
1793     {
1794       aTolerance /= 2;
1795       if( aTolerance < 1 )
1796         break;
1797     }
1798     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1799
1800     aHue = (int)( 360.0 * rand() / RAND_MAX );
1801     //std::cout << "Hue = " << aHue << std::endl;
1802
1803     //std::cout << "Auto colors : ";
1804     bool ok = true;
1805     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1806     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1807     for( ; it != itEnd; ++it )
1808     {
1809       SALOMEDS::Color anAutoColor = *it;
1810       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1811
1812       int h, s, v;
1813       aQColor.getHsv( &h, &s, &v );
1814       //std::cout << h << " ";
1815       if( abs( h - aHue ) < aTolerance )
1816       {
1817         ok = false;
1818         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1819         break;
1820       }
1821     }
1822     //std::cout << std::endl;
1823
1824     if( ok )
1825       break;
1826   }
1827
1828   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1829   QColor aColor;
1830   aColor.setHsv( aHue, 255, 255 );
1831
1832   SALOMEDS::Color aSColor;
1833   aSColor.R = (double)aColor.red() / 255.0;
1834   aSColor.G = (double)aColor.green() / 255.0;
1835   aSColor.B = (double)aColor.blue() / 255.0;
1836
1837   return aSColor;
1838 }
1839
1840 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1841                                              const QString& entry,
1842                                              SALOME_View* view )
1843 {
1844   // get default properties for the explicitly specified default view type
1845   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1846
1847   if ( study && view ) {
1848     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1849     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1850     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1851   
1852     if ( viewModel && viewId != -1 ) {
1853       // get properties from the study
1854       PropMap storedMap = study->getObjectPropMap( viewId, entry );
1855       // overwrite default properties from stored ones (that are specified)
1856       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1857         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1858           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
1859                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1860       }
1861       // ... specific processing for color
1862       // ... current implementation is to use same stored color for all aspects
1863       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1864       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1865         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1866         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1867         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1868         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1869         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1870       }
1871
1872       if ( !entry.isEmpty() ) {
1873         // get CORBA reference to geom object
1874         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1875         if ( SO ) {
1876           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1877           if ( !CORBA::is_nil( object ) ) {
1878             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1879             // check that geom object has color properly set
1880             bool hasColor = false;
1881             SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1882             // set color from geometry object (only once, if it is not yet set in GUI)
1883             // current implementation is to use same color for all aspects
1884             // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1885             if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1886               QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1887               propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
1888               propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1889               propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
1890               propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
1891               propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
1892             }
1893             // check that object has point marker properly set
1894             GEOM::marker_type mType = geomObject->GetMarkerType();
1895             GEOM::marker_size mSize = geomObject->GetMarkerSize();
1896             int mTextureId = geomObject->GetMarkerTexture();
1897             bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
1898                              ( mType == GEOM::MT_USER && mTextureId > 0 );
1899             // set point marker from geometry object (only once, if it is not yet set in GUI)
1900             if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
1901               if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
1902                 // standard type
1903                 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1904                                 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
1905               }
1906               else if ( mType == GEOM::MT_USER ) {
1907                 // custom texture
1908                 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
1909               }
1910             }
1911           }
1912         }
1913       }
1914     }
1915   }
1916   return propMap;
1917 }
1918
1919 PropMap GEOM_Displayer::getDefaultPropertyMap()
1920 {
1921   PropMap propMap;
1922
1923   // get resource manager
1924   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1925
1926   // fill in the properties map with default values
1927
1928   // - visibility (false by default)
1929   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
1930
1931   // - nb isos (take default value from preferences)
1932   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
1933                   QString( "%1%2%3" ).
1934                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
1935                   arg( GEOM::subSectionSeparator() ).
1936                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
1937
1938   // - transparency (opacity = 1-transparency)
1939   propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
1940
1941   // - display mode (take default value from preferences)
1942   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
1943                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
1944
1945   // - show edges direction flag (false by default)
1946   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
1947
1948   // - shading color (take default value from preferences)
1949   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
1950                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
1951
1952   // - wireframe color (take default value from preferences)
1953   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
1954                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
1955
1956   // - standalone edges color (take default value from preferences)
1957   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
1958                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
1959
1960   // - free boundaries color (take default value from preferences)
1961   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
1962                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
1963
1964   // - points color (take default value from preferences)
1965   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
1966                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
1967
1968   // - isos color (take default value from preferences)
1969   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
1970                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
1971
1972   // - outlines color (take default value from preferences)
1973   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
1974                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
1975
1976   // - deflection coefficient (take default value from preferences)
1977   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
1978                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
1979
1980   // - material (take default value from preferences)
1981   Material_Model material;
1982   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
1983   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
1984
1985   // - edge width (take default value from preferences)
1986   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
1987                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
1988
1989   // - isos width (take default value from preferences)
1990   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
1991                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
1992
1993   // - point marker (take default value from preferences)
1994   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1995                   QString( "%1%2%3" ).
1996                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
1997                   arg( GEOM::subSectionSeparator() ).
1998                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
1999
2000   // - top-level flag (false by default)
2001   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2002
2003   return propMap;
2004 }
2005
2006 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2007   SALOMEDS::Color aSColor;
2008   hasColor = false;
2009
2010   SUIT_Session* session = SUIT_Session::session();
2011   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2012
2013   if ( app && !theGeomObject->_is_nil()) {
2014     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2015
2016     if ( study ) {
2017       _PTR(Study) aStudy = study->studyDS();
2018       aSColor = theGeomObject->GetColor();
2019       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2020       if ( !hasColor ) {
2021 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2022         bool general_autocolor = true;
2023 #else                    // auto-color for groups only
2024         bool general_autocolor = false;
2025 #endif                   // GENERAL_AUTOCOLOR
2026         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2027           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2028           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2029 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2030             aSColor = getPredefinedUniqueColor();
2031             hasColor = true;
2032 #else                    // old algorithm  for auto-colors
2033             QList<SALOMEDS::Color> aReservedColors;
2034             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2035             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2036             if ( aMainSObject ) {
2037               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2038               for ( ; it->More(); it->Next() ) {
2039                 _PTR(SObject) aChildSObject( it->Value() );
2040                 GEOM::GEOM_Object_var aChildObject =
2041                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2042                 if ( CORBA::is_nil( aChildObject ) )
2043                   continue;
2044
2045                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2046                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2047                   aReservedColors.append( aReservedColor );
2048               }
2049             }
2050             aSColor = getUniqueColor( aReservedColors );
2051             hasColor = true;
2052 #endif                   // SIMPLE_AUTOCOLOR
2053           }
2054         }
2055       }
2056     }
2057   }
2058   return aSColor;
2059 }
2060
2061
2062 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2063                                        const bool eraseOnlyChildren) {
2064   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2065   if ( !app )
2066     return;
2067
2068   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2069   if ( !appStudy )
2070     return;
2071
2072   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2073
2074   if( !parent)
2075     return;
2076
2077   // Erase from all views
2078   QList<SALOME_View*> views;
2079   SALOME_View* view;
2080   ViewManagerList vmans = app->viewManagers();
2081   SUIT_ViewManager* vman;
2082   foreach ( vman, vmans ) {
2083     SUIT_ViewModel* vmod = vman->getViewModel();
2084     view = dynamic_cast<SALOME_View*> ( vmod );
2085     if ( view )
2086       views.append( view );
2087   }
2088
2089   if( views.count() == 0 )
2090     return;
2091
2092   //Erase childrens w/o update views
2093   DataObjectList listObj = parent->children( true );
2094   SUIT_DataObject* obj;
2095   foreach( obj, listObj ) {
2096     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2097     if(l_obj)
2098       foreach ( view, views ) {
2099       Handle(SALOME_InteractiveObject) anIO =
2100         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2101       Erase(anIO, false, false, view);
2102     }
2103   }
2104
2105   //Erase parent with view update or repaint views
2106   foreach ( view, views ) {
2107     if(!eraseOnlyChildren)
2108       Erase(theIO, false, true, view);
2109     else
2110       view->Repaint();
2111   }
2112 }