Salome HOME
Merge from V6_main 01/04/2013
[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         static int TextureId = 0;
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                                  ++TextureId,
744                                  aWidth, aHeight,
745                                  aTexture );
746         AISShape->Attributes()->SetPointAspect( aTextureAspect );
747       }
748     }
749   }
750
751   if ( create && !isTemporary && aMgrId != -1 ) {
752     // set properties to the study
753     study->setObjectPropMap( aMgrId, entry, propMap );
754   }
755
756   // AISShape->SetName(???); ??? necessary to set name ???
757 }
758
759 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
760 {
761   // check that actor is not null
762   if ( !actor ) return;
763   
764   // check that study is active
765   SalomeApp_Study* study = getStudy();
766   if ( !study ) return;
767
768   // set interactive object
769
770   Handle( SALOME_InteractiveObject ) anIO;
771
772   if ( !myIO.IsNull() ) {
773     actor->setIO( myIO );
774     anIO = myIO;
775   }
776   else if ( !myName.empty() ) {
777     // workaround to allow selection of temporary objects
778     static int tempId = 0;
779     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
780     actor->setIO( anIO );
781   }
782
783   // presentation study entry (empty for temporary objects like preview)
784   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
785   // flag: temporary object
786   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
787   // currently active view window's ID (-1 if no active view)
788   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
789
790   // get presentation properties
791   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
792   QColor c;
793
794   /////////////////////////////////////////////////////////////////////////
795   // VSR: for VTK viewer currently deflection coefficient is hardcoded
796   //      due to performance problem
797   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
798   /////////////////////////////////////////////////////////////////////////
799   if ( !actor->getTopo().IsSame( myShape ) )
800     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
801
802   // set material
803   Material_Model material;
804   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
805   std::vector<vtkProperty*> mprops;
806   mprops.push_back( material.getMaterialVTKProperty( true ) );
807   mprops.push_back( material.getMaterialVTKProperty( false) );
808   actor->SetMaterial( mprops );
809
810   // set iso-lines properties
811
812   // - set number of iso-lines
813   int nbIsos[2]= { 1, 1 };
814   QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
815   nbIsos[0] = isos[0].toInt();
816   nbIsos[1] = isos[1].toInt();
817   actor->SetNbIsos( nbIsos );
818
819   // - set iso-lines width
820   actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
821
822   // - set iso-lines color
823   c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
824   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
825
826   // set colors
827
828   if ( HasColor()  ) {
829     // - same color for all sub-actors
830     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
831     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
832   }
833   else {
834     // shading color (for non-physical materials)
835     if ( !material.isPhysical() ) {
836       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
837       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
838       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
839     }
840
841     // - standalone edge color
842     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
843     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
844
845     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
846     // - shared edges color ???
847     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
848
849     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
850     // - free edges color ???
851     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
852
853     // - point color
854     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
855     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
856   }
857
858   // - color for edges in shading+edges mode
859   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
860   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
861
862   // set opacity
863   actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
864
865   // set line width
866   actor->SetWidth( HasWidth() ?
867                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
868                    GetWidth() :
869                    // libe width from properties
870                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
871   
872   // set display vectors flag
873   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
874
875   // set display mode
876   int displayMode = HasDisplayMode() ? 
877     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
878     GetDisplayMode() :
879     // display mode from properties
880     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
881
882   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
883   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
884   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
885   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
886
887   if ( displayMode == 2 )
888       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
889       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
890     displayMode++;
891   actor->setDisplayMode( displayMode );
892
893   if ( myToActivate )
894     actor->PickableOn();
895   else
896     actor->PickableOff();
897
898   if ( create && !isTemporary && aMgrId != -1 ) {
899     // set properties to the study
900     study->setObjectPropMap( aMgrId, entry, propMap );
901   }
902 }
903
904 //=================================================================
905 /*!
906  *  GEOM_Displayer::Erase
907  *  Calls Erase() method for each object in the given list
908  */
909 //=================================================================
910 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
911                             const bool forced,
912                             const bool updateViewer )
913 {
914   SALOME_ListIteratorOfListIO Iter( theIOList );
915   for ( ; Iter.More(); Iter.Next() )
916     Erase( Iter.Value(), forced, false );
917
918   if ( updateViewer )
919     UpdateViewer();
920 }
921
922 //=================================================================
923 /*!
924  *  GEOM_Displayer::Redisplay
925  *  Calls Redisplay() method for each object in the given list
926  */
927 //=================================================================
928 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer )
929 {
930   SALOME_ListIteratorOfListIO Iter( theIOList );
931   for ( ; Iter.More(); Iter.Next() )
932     Redisplay( Iter.Value(), false );
933
934   if ( updateViewer )
935     UpdateViewer();
936 }
937
938 //=================================================================
939 /*!
940  *  GEOM_Displayer::Update
941  *  Update OCC presentaion
942  *  [ Reimplemented from SALOME_Displayer ]
943  */
944 //=================================================================
945 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
946 {
947   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
948   SalomeApp_Study* study = getStudy();
949
950   if ( !occPrs || myShape.IsNull() || !study )
951     return;
952
953   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
954   {
955     // 
956     // specific processing for local coordinate system presentation
957     // 
958
959     TopoDS_Face aFace = TopoDS::Face( myShape );
960     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
961     if ( !aPlane.IsNull() )
962     {
963       gp_Ax3 aPos = aPlane->Pln().Position();
964       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
965
966       Handle(GEOM_AISTrihedron) aTrh;
967
968       if ( occPrs->IsNull() )
969       {
970         // new presentation is being created
971         aTrh = new GEOM_AISTrihedron( aPlc );
972         occPrs->AddObject( aTrh );
973       }
974       else
975       {
976         // presentation is being updated
977         AIS_ListOfInteractive aList;
978         occPrs->GetObjects( aList );
979         AIS_ListIteratorOfListOfInteractive anIter( aList );
980         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
981           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
982         }
983       }
984         
985       if ( !aTrh.IsNull() ) {
986         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
987         if ( HasColor() )
988           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
989         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
990         if ( HasWidth() )
991           aTrh->SetWidth( GetWidth() );
992         
993         if ( !myIO.IsNull() )
994         {
995           aTrh->setIO( myIO );
996           aTrh->SetOwner( myIO );
997         }
998         aTrh->SetComponent( aPlc );
999         aTrh->SetToUpdate();
1000       }
1001       occPrs->SetToActivate( ToActivate() );
1002     }
1003   }
1004   else
1005   {
1006     // 
1007     // processing for usual geometry presentation
1008     // 
1009
1010     // if presentation is empty we try to create new one
1011     if ( occPrs->IsNull() )
1012     {
1013       // create presentation (specific for vectors)
1014       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1015                                                                  : new GEOM_AISShape ( myShape, "" );
1016       // update shape properties
1017       updateShapeProperties( AISShape, true );
1018
1019       // add shape to the presentation
1020       occPrs->AddObject( AISShape );
1021
1022       // In accordance with ToActivate() value object will be activated/deactivated
1023       // when it will be displayed
1024       occPrs->SetToActivate( ToActivate() );
1025
1026       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1027         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1028
1029         // create additional wireframe shape
1030         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1031         aWirePrs->SetWidth(AISShape->Width());
1032         if ( !myIO.IsNull() ) {
1033           aWirePrs->setIO( myIO );
1034           aWirePrs->SetOwner( myIO );
1035         }
1036
1037         // add shape to the presentation
1038         occPrs->AddObject( aWirePrs );
1039       }
1040     }
1041     // if presentation is found -> set again shape for it
1042     else
1043     {
1044       AIS_ListOfInteractive IOList;
1045       occPrs->GetObjects( IOList );
1046       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1047       for ( ; Iter.More(); Iter.Next() )
1048       {
1049         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1050         if ( AISShape.IsNull() )
1051           continue;
1052
1053         // re-set shape (it might be changed)
1054         if ( AISShape->Shape() != myShape )
1055           AISShape->Set( myShape );
1056
1057         // update shape properties
1058         updateShapeProperties( AISShape, false );
1059
1060         // force updating
1061         AISShape->UpdateSelection();
1062         AISShape->SetToUpdate();
1063       }
1064     }
1065   }
1066 }
1067
1068 //=================================================================
1069 /*!
1070  *  GEOM_Displayer::Update
1071  *  Update VTK presentaion
1072  *  [ Reimplemented from SALOME_Displayer ]
1073  */
1074 //=================================================================
1075 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1076 {
1077   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1078   SalomeApp_Study* study = getStudy();
1079
1080   if ( !vtkPrs || myShape.IsNull() || !study )
1081     return;
1082
1083   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1084   {
1085     // 
1086     // specific processing for local coordinate system presentation
1087     // 
1088
1089     TopoDS_Face aFace = TopoDS::Face( myShape );
1090     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1091     if ( !aPlane.IsNull() ) {
1092       gp_Ax3 aPos = aPlane->Pln().Position();
1093       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1094
1095       GEOM_VTKTrihedron* aTrh = 0;
1096
1097       if ( vtkPrs->IsNull() ) {
1098         // new presentation is being created
1099         aTrh = GEOM_VTKTrihedron::New();
1100         vtkPrs->AddObject( aTrh );
1101       }
1102       else {
1103         // presentation is being updated
1104         vtkActorCollection* actors = vtkPrs->GetObjects();
1105         if ( actors ) {
1106           actors->InitTraversal();
1107           vtkActor* a = actors->GetNextActor();
1108           while ( a && !aTrh ) {
1109             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1110             a = actors->GetNextActor();
1111           }
1112         }
1113       }
1114       
1115       if ( aTrh ) {
1116         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1117         if ( HasColor() ) {
1118           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1119           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1120         }
1121 #ifdef VTK_TRIHEDRON_WIDTH
1122         // 
1123         // VSR: currently isn't supported
1124         //
1125         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1126         if ( HasWidth() )
1127           aTrh->SetWidth( GetWidth() );
1128 #endif
1129
1130         if ( !myIO.IsNull() )
1131           aTrh->setIO( myIO );
1132
1133         aTrh->SetPlacement( aPlc );
1134       }
1135     }
1136   }
1137   else
1138   {
1139     // 
1140     // processing for usual geometry presentation
1141     // 
1142
1143     // if presentation is empty we try to create new one
1144     if ( vtkPrs->IsNull() )
1145     {
1146       // create an actor
1147       GEOM_Actor* actor = GEOM_Actor::New();
1148       // update actor properties
1149       updateActorProperties( actor, true );
1150       // add actor to the presentation
1151       vtkPrs->AddObject( actor );
1152     }
1153     else {
1154       // presentation is being updated
1155       vtkActorCollection* actors = vtkPrs->GetObjects();
1156       if ( actors ) {
1157         actors->InitTraversal();
1158         vtkActor* a = actors->GetNextActor();
1159         while ( a ) {
1160           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1161           if ( actor ) {
1162             // update actor properties
1163             updateActorProperties( actor, false );
1164             a = actors->GetNextActor();
1165           }
1166         }
1167       }
1168     }
1169   }
1170 }
1171
1172 //=================================================================
1173 /*!
1174  *  GEOM_Displayer::BuildPrs
1175  *  Build presentation accordint to the current viewer type
1176  */
1177 //=================================================================
1178 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1179 {
1180   if ( theObj->_is_nil() )
1181     return 0;
1182
1183   myViewFrame = GetActiveView();
1184   if ( myViewFrame == 0 )
1185     return 0;
1186
1187   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1188   if ( aPrs == 0 )
1189     return 0;
1190
1191   internalReset();
1192   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1193   myType = theObj->GetType();
1194
1195   // Update presentation
1196   UpdatePrs( aPrs );
1197
1198   return aPrs;
1199 }
1200
1201 //=================================================================
1202 /*!
1203  *  GEOM_Displayer::BuildPrs
1204  *  Build presentation accordint to the current viewer type
1205  */
1206 //=================================================================
1207 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1208 {
1209   myViewFrame = GetActiveView();
1210   if ( theShape.IsNull() || myViewFrame == 0 )
1211     return 0;
1212
1213   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1214   if ( aPrs == 0 )
1215     return 0;
1216
1217   internalReset();
1218   setShape( theShape );
1219   myType = -1;
1220
1221   UpdatePrs( aPrs );
1222
1223   return aPrs;
1224 }
1225
1226 //=================================================================
1227 /*!
1228  *  GEOM_Displayer::buildPresentation
1229  *  Builds/finds object's presentation for the current viewer
1230  *  Calls corresponding Update() method by means of double dispatch
1231  *  [ internal ]
1232  */
1233 //=================================================================
1234 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1235                                                SALOME_View* theViewFrame )
1236 {
1237   SALOME_Prs* prs = 0;
1238   internalReset();
1239
1240   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1241
1242   if ( myViewFrame )
1243   {
1244     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1245     if ( prs )
1246     {
1247       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1248       theIO->setEntry( entry.toLatin1().constData() );
1249       if ( !theIO.IsNull() )
1250       {
1251         // set interactive object
1252         setIO( theIO );
1253         //  Find SOBject (because shape should be published previously)
1254         SUIT_Session* session = SUIT_Session::session();
1255         SUIT_Application* app = session->activeApplication();
1256         if ( app )
1257         {
1258           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1259           if ( study )
1260           {
1261             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1262             if ( SO )
1263             {
1264               // get CORBA reference to data object
1265               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1266               if ( !CORBA::is_nil( object ) )
1267               {
1268                 // downcast to GEOM object
1269                 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object );
1270                 if ( !GeomObject->_is_nil() )
1271                 {
1272                   // finally set shape
1273                   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1274                   myType = GeomObject->GetType();
1275                 }
1276               }
1277             }
1278           }
1279         }
1280       }
1281       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1282     }
1283   }
1284   return prs;
1285 }
1286
1287 //=================================================================
1288 /*!
1289  *  GEOM_Displayer::buildSubshapePresentation
1290  *  Builds/finds object's presentation for the current viewer
1291  *  Calls corresponding Update() method by means of double dispatch
1292  *  For not published objects (for Mantis issue 0020435)
1293  */
1294 //=================================================================
1295 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1296                                                       const QString& entry,
1297                                                       SALOME_View* theViewFrame)
1298 {
1299   SALOME_Prs* prs = 0;
1300   internalReset();
1301
1302   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1303
1304   if (myViewFrame)
1305   {
1306     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1307     if (prs)
1308     {
1309       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1310       theIO->setEntry(entry.toLatin1().constData());
1311       if (!theIO.IsNull())
1312       {
1313         // set interactive object
1314         setIO(theIO);
1315         // finally set shape
1316         setShape(aShape);
1317         myType = GEOM_SUBSHAPE;
1318       }
1319       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1320     }
1321   }
1322   return prs;
1323 }
1324
1325 //=================================================================
1326 /*!
1327  *  GEOM_Displayer::internalReset
1328  *  Resets internal data
1329  *  [internal]
1330  */
1331 //=================================================================
1332 void GEOM_Displayer::internalReset()
1333 {
1334   myIO.Nullify();
1335   myShape.Nullify();
1336 }
1337
1338 //=================================================================
1339 /*!
1340  *  GEOM_Displayer::LocalSelection
1341  *  Activate selection of CAD shapes with activisation of selection
1342  *  of their sub-shapes (with opened local context for OCC viewer)
1343  */
1344 //=================================================================
1345 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1346 {
1347   SUIT_Session* session = SUIT_Session::session();
1348   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1349   if ( !app )
1350     return;
1351
1352   LightApp_SelectionMgr* sm = app->selectionMgr();
1353
1354   // remove all filters from selection
1355   sm->clearFilters();
1356
1357   SALOME_View* vf = GetActiveView();
1358   if ( vf ) {
1359     if (!theIO.IsNull() && !vf->isVisible(theIO))
1360       Display(theIO);
1361     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1362     vf->LocalSelection( prs, theMode );
1363     delete prs;  // delete presentation because displayer is its owner
1364   }
1365 }
1366
1367 //=================================================================
1368 /*!
1369  *  GEOM_Displayer::globalSelection
1370  *  Activate selection of CAD shapes without activisation of selection
1371  *  of their sub-shapes (without opened local context for OCC viewer)
1372  */
1373 //=================================================================
1374 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1375 {
1376   TColStd_MapOfInteger aModes;
1377   aModes.Add( theMode );
1378   GlobalSelection( aModes, update );
1379 }
1380
1381 //=================================================================
1382 /*!
1383  *  GEOM_Displayer::globalSelection
1384  *  Activate selection of CAD shapes without activisation of selection
1385  *  of their sub-shapes (without opened local context for OCC viewer)
1386  */
1387 //=================================================================
1388 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1389                                       const bool update, const QList<int>* theSubShapes )
1390 {
1391   SUIT_Session* session = SUIT_Session::session();
1392   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1393   if ( !app )
1394     return;
1395
1396   SALOME_View* vf = GetActiveView();
1397   if ( vf == 0 )
1398     return;
1399
1400   // Close local context
1401   vf->GlobalSelection( update );
1402
1403   // Set selection filters in accordance with current mode
1404   LightApp_SelectionMgr* sm = app->selectionMgr();
1405   if ( !sm )
1406     return;
1407
1408   // Remove from selection temporary objects if necessary
1409   if ( !theModes.Contains( GEOM_PREVIEW ) )
1410     clearTemporary( sm );
1411
1412   //@ aSel->ClearIndex();
1413
1414   sm->clearFilters();
1415
1416   // Remove filters from AIS_InteractiveContext
1417   Handle(AIS_InteractiveContext) ic;
1418   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1419   if ( viewer )
1420     {
1421       ic = viewer->getAISContext();
1422       if ( !ic.IsNull() )
1423         ic->RemoveFilters();
1424     }
1425
1426   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1427     return;
1428
1429   SUIT_SelectionFilter* aFilter;
1430   if ( theModes.Extent() == 1 )
1431     {
1432       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1433
1434       if ( aMode == GEOM_COMPOUNDFILTER )
1435         aFilter = getComplexFilter( theSubShapes );
1436       else
1437         aFilter = getFilter( aMode );
1438     }
1439   else if ( theModes.Extent() > 1 )
1440     {
1441       TColStd_MapOfInteger aTopAbsModes;
1442       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1443       QList<SUIT_SelectionFilter*> aListOfFilters;
1444       for ( ; anIter.More(); anIter.Next() )
1445         {
1446           SUIT_SelectionFilter* aFilter;
1447           int aMode = anIter.Key();
1448           if ( aMode == GEOM_COMPOUNDFILTER )
1449             aFilter = getComplexFilter( theSubShapes );
1450           else
1451             aFilter = getFilter( aMode );
1452
1453           if ( aFilter )
1454             aListOfFilters.append( aFilter );
1455         }
1456
1457       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1458     }
1459   else
1460     return;
1461
1462   if ( aFilter )
1463     {
1464       sm->installFilter( aFilter );
1465       if ( !ic.IsNull() )
1466         {
1467           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1468           ic->AddFilter( anOCCFilter );
1469         }
1470     }
1471 }
1472
1473 //=================================================================
1474 /*!
1475  *  GEOM_Displayer::LocalSelection
1476  *  Activate selection of CAD shapes with activisation of selection
1477  *  of their sub-shapes (with opened local context for OCC viewer)
1478  */
1479 //=================================================================
1480 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1481 {
1482   SALOME_ListIteratorOfListIO Iter( theIOList );
1483   for ( ; Iter.More(); Iter.Next() )
1484     LocalSelection( Iter.Value(), theMode );
1485 }
1486
1487 //=================================================================
1488 /*!
1489  *  GEOM_Displayer::BeforeDisplay
1490  *  Called before displaying of pars. Close local context
1491  *  [ Reimplemented from SALOME_Displayer ]
1492  */
1493 //=================================================================
1494 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1495 {
1496   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1497   if ( vf )
1498   {
1499     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1500     if ( !ic.IsNull() )
1501     {
1502       if ( ic->HasOpenedContext() )
1503       ic->CloseAllContexts();
1504     }
1505   }
1506 }
1507
1508 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1509 {
1510   SalomeApp_Study* aStudy = getStudy();
1511   if (!aStudy) return;
1512   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1513   if ( vf && !p->IsNull() ) {
1514     int aMgrId = getViewManagerId( vf );
1515     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1516     const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
1517     if ( !ic.IsNull() && prs ) {
1518       AIS_ListOfInteractive objects;
1519       prs->GetObjects( objects );
1520       AIS_ListIteratorOfListOfInteractive it( objects );
1521       for ( ; it.More(); it.Next() ) {
1522         Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
1523         if ( sh.IsNull() ) continue;
1524         Handle(SALOME_InteractiveObject) IO = sh->getIO();
1525         if ( IO.IsNull() ) continue;
1526         PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
1527         if ( aPropMap.contains( GEOM::propertyName( GEOM::Transparency ) ) ) {
1528           double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble();
1529           ic->SetTransparency( sh, transparency, true );
1530         }
1531       }
1532     }
1533   }
1534 }
1535
1536 //=================================================================
1537 /*!
1538  *  GEOM_Displayer::SetColor
1539  *  Set color for shape displaying. If it is equal -1 then default color is used.
1540  *  Available values are from Quantity_NameOfColor enumeration
1541  */
1542 //=================================================================
1543 void GEOM_Displayer::SetColor( const int color )
1544 {
1545   if ( color == -1 )
1546     UnsetColor();
1547   else
1548   {
1549     myColor = color;
1550     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1551   }
1552 }
1553
1554 int GEOM_Displayer::GetColor() const
1555 {
1556   return myColor;
1557 }
1558
1559 bool GEOM_Displayer::HasColor() const
1560 {
1561   return myColor != -1;
1562 }
1563
1564 void GEOM_Displayer::UnsetColor()
1565 {
1566   myColor = -1;
1567
1568   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1569   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1570   myShadingColor = SalomeApp_Tools::color( col );
1571 }
1572
1573 //=================================================================
1574 /*!
1575  *  GEOM_Displayer::SetTexture
1576  *  Set color for shape displaying. If it is equal -1 then default color is used.
1577  *  Available values are from Quantity_NameOfColor enumeration
1578  */
1579 //=================================================================
1580 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1581 {
1582   if(texureFileName!="")
1583   {
1584     myTexture = texureFileName;
1585   }
1586 }
1587
1588 bool GEOM_Displayer::HasTexture() const
1589 {
1590   return myTexture != "";
1591 }
1592
1593 std::string GEOM_Displayer::GetTexture() const
1594 {
1595   return myTexture;
1596 }
1597
1598 //=================================================================
1599 /*!
1600  *  GEOM_Displayer::SetWidth
1601  *  Set width of shape displaying. If it is equal -1 then default width is used.
1602  */
1603 //=================================================================
1604 void GEOM_Displayer::SetWidth( const double width )
1605 {
1606   myWidth = width;
1607 }
1608
1609 double GEOM_Displayer::GetWidth() const
1610 {
1611   return myWidth;
1612 }
1613
1614 bool GEOM_Displayer::HasWidth() const
1615 {
1616   return myWidth != -1;
1617 }
1618
1619 void GEOM_Displayer::UnsetWidth()
1620 {
1621   myWidth = -1;
1622 }
1623
1624
1625 int GEOM_Displayer::GetIsosWidth() const
1626 {
1627   return myIsosWidth;
1628 }
1629
1630 void GEOM_Displayer::SetIsosWidth(const int width)
1631 {
1632   myIsosWidth = width;
1633 }
1634
1635 bool GEOM_Displayer::HasIsosWidth() const
1636 {
1637   return myIsosWidth != -1;
1638 }
1639
1640
1641 //=================================================================
1642 /*!
1643  *  GEOM_Displayer::SetToActivate
1644  *  This method is used for activisation/deactivisation of objects to be displayed
1645  */
1646 //=================================================================
1647 void GEOM_Displayer::SetToActivate( const bool toActivate )
1648 {
1649   myToActivate = toActivate;
1650 }
1651 bool GEOM_Displayer::ToActivate() const
1652 {
1653   return myToActivate;
1654 }
1655
1656 //=================================================================
1657 /*!
1658  *  GEOM_Displayer::clearTemporary
1659  *  Removes from selection temporary objects
1660  */
1661 //=================================================================
1662 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1663 {
1664   SALOME_ListIO selected, toSelect;
1665   theSelMgr->selectedObjects( selected );
1666
1667   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1668     Handle(SALOME_InteractiveObject) io = it.Value();
1669     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1670       toSelect.Append( it.Value() );
1671   }
1672
1673   theSelMgr->setSelectedObjects( toSelect, true );
1674 }
1675
1676 void GEOM_Displayer::SetName( const char* theName )
1677 {
1678   myName = theName;
1679 }
1680
1681 void GEOM_Displayer::UnsetName()
1682 {
1683   myName = "";
1684 }
1685
1686 SalomeApp_Study* GEOM_Displayer::getStudy() const
1687 {
1688   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1689 }
1690
1691 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1692 {
1693   myIO = theIO;
1694 }
1695
1696 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1697 {
1698   myShape = theShape;
1699 }
1700
1701 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1702 {
1703   return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type();
1704 }
1705
1706 int GEOM_Displayer::SetDisplayMode( const int theMode )
1707 {
1708   int aPrevMode = myDisplayMode;
1709   if ( theMode != -1 ) {
1710     myDisplayMode = theMode;
1711     myHasDisplayMode = true;
1712   }
1713   else {
1714     UnsetDisplayMode();
1715   }
1716   return aPrevMode;
1717 }
1718
1719 int GEOM_Displayer::GetDisplayMode() const
1720 {
1721   return myDisplayMode;
1722 }
1723
1724 int GEOM_Displayer::UnsetDisplayMode()
1725 {
1726   int aPrevMode = myDisplayMode;
1727   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1728   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
1729   myHasDisplayMode = false;
1730   return aPrevMode;
1731 }
1732
1733 bool GEOM_Displayer::HasDisplayMode() const
1734 {
1735   return myHasDisplayMode;
1736 }
1737
1738 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
1739 {
1740   static QList<QColor> colors;
1741
1742   if ( colors.isEmpty() ) {
1743
1744     for (int s = 0; s < 2 ; s++)
1745     {
1746       for (int v = 100; v >= 40; v = v - 20)
1747       {
1748         for (int h = 0; h < 359 ; h = h + 60)
1749         {
1750           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
1751         }
1752       }
1753     }
1754   }
1755
1756   static int currentColor = 0;
1757
1758   SALOMEDS::Color color;
1759   color.R = (double)colors[currentColor].red()   / 255.0;
1760   color.G = (double)colors[currentColor].green() / 255.0;
1761   color.B = (double)colors[currentColor].blue()  / 255.0;
1762
1763   currentColor = (currentColor+1) % colors.count();
1764
1765   return color;
1766 }
1767
1768 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
1769 {
1770   int aHue = -1;
1771   int aTolerance = 64;
1772   int anIterations = 0;
1773   int aPeriod = 5;
1774
1775   while( 1 )
1776   {
1777     anIterations++;
1778     if( anIterations % aPeriod == 0 )
1779     {
1780       aTolerance /= 2;
1781       if( aTolerance < 1 )
1782         break;
1783     }
1784     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
1785
1786     aHue = (int)( 360.0 * rand() / RAND_MAX );
1787     //std::cout << "Hue = " << aHue << std::endl;
1788
1789     //std::cout << "Auto colors : ";
1790     bool ok = true;
1791     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
1792     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
1793     for( ; it != itEnd; ++it )
1794     {
1795       SALOMEDS::Color anAutoColor = *it;
1796       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
1797
1798       int h, s, v;
1799       aQColor.getHsv( &h, &s, &v );
1800       //std::cout << h << " ";
1801       if( abs( h - aHue ) < aTolerance )
1802       {
1803         ok = false;
1804         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
1805         break;
1806       }
1807     }
1808     //std::cout << std::endl;
1809
1810     if( ok )
1811       break;
1812   }
1813
1814   //std::cout << "Hue of the returned color = " << aHue << std::endl;
1815   QColor aColor;
1816   aColor.setHsv( aHue, 255, 255 );
1817
1818   SALOMEDS::Color aSColor;
1819   aSColor.R = (double)aColor.red() / 255.0;
1820   aSColor.G = (double)aColor.green() / 255.0;
1821   aSColor.B = (double)aColor.blue() / 255.0;
1822
1823   return aSColor;
1824 }
1825
1826 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
1827                                              const QString& entry,
1828                                              SALOME_View* view )
1829 {
1830   // get default properties for the explicitly specified default view type
1831   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
1832
1833   if ( study && view ) {
1834     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
1835     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
1836     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
1837   
1838     if ( viewModel && viewId != -1 ) {
1839       // get properties from the study
1840       PropMap storedMap = study->getObjectPropMap( viewId, entry );
1841       // overwrite default properties from stored ones (that are specified)
1842       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
1843         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
1844           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
1845                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
1846       }
1847       // ... specific processing for color
1848       // ... current implementation is to use same stored color for all aspects
1849       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1850       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1851         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1852         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1853         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1854         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1855         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
1856       }
1857
1858       if ( !entry.isEmpty() ) {
1859         // get CORBA reference to geom object
1860         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
1861         if ( SO ) {
1862           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
1863           if ( !CORBA::is_nil( object ) ) {
1864             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
1865             // check that geom object has color properly set
1866             bool hasColor = false;
1867             SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
1868             // set color from geometry object (only once, if it is not yet set in GUI)
1869             // current implementation is to use same color for all aspects
1870             // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
1871             if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
1872               QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
1873               propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
1874               propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
1875               propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
1876               propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
1877               propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
1878             }
1879             // check that object has point marker properly set
1880             GEOM::marker_type mType = geomObject->GetMarkerType();
1881             GEOM::marker_size mSize = geomObject->GetMarkerSize();
1882             int mTextureId = geomObject->GetMarkerTexture();
1883             bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
1884                              ( mType == GEOM::MT_USER && mTextureId > 0 );
1885             // set point marker from geometry object (only once, if it is not yet set in GUI)
1886             if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
1887               if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
1888                 // standard type
1889                 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1890                                 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
1891               }
1892               else if ( mType == GEOM::MT_USER ) {
1893                 // custom texture
1894                 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
1895               }
1896             }
1897           }
1898         }
1899       }
1900     }
1901   }
1902   return propMap;
1903 }
1904
1905 PropMap GEOM_Displayer::getDefaultPropertyMap()
1906 {
1907   PropMap propMap;
1908
1909   // get resource manager
1910   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1911
1912   // fill in the properties map with default values
1913
1914   // - visibility (false by default)
1915   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
1916
1917   // - nb isos (take default value from preferences)
1918   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
1919                   QString( "%1%2%3" ).
1920                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
1921                   arg( GEOM::subSectionSeparator() ).
1922                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
1923
1924   // - transparency (opacity = 1-transparency)
1925   propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
1926
1927   // - display mode (take default value from preferences)
1928   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
1929                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
1930
1931   // - show edges direction flag (false by default)
1932   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
1933
1934   // - shading color (take default value from preferences)
1935   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
1936                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
1937
1938   // - wireframe color (take default value from preferences)
1939   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
1940                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
1941
1942   // - standalone edges color (take default value from preferences)
1943   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
1944                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
1945
1946   // - free boundaries color (take default value from preferences)
1947   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
1948                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
1949
1950   // - points color (take default value from preferences)
1951   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
1952                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
1953
1954   // - isos color (take default value from preferences)
1955   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
1956                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
1957
1958   // - outlines color (take default value from preferences)
1959   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
1960                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
1961
1962   // - deflection coefficient (take default value from preferences)
1963   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
1964                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
1965
1966   // - material (take default value from preferences)
1967   Material_Model material;
1968   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
1969   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
1970
1971   // - edge width (take default value from preferences)
1972   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
1973                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
1974
1975   // - isos width (take default value from preferences)
1976   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
1977                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
1978
1979   // - point marker (take default value from preferences)
1980   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
1981                   QString( "%1%2%3" ).
1982                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
1983                   arg( GEOM::subSectionSeparator() ).
1984                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
1985
1986   // - top-level flag (false by default)
1987   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
1988
1989   return propMap;
1990 }
1991
1992 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
1993   SALOMEDS::Color aSColor;
1994   hasColor = false;
1995
1996   SUIT_Session* session = SUIT_Session::session();
1997   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1998
1999   if ( app && !theGeomObject->_is_nil()) {
2000     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2001
2002     if ( study ) {
2003       _PTR(Study) aStudy = study->studyDS();
2004       aSColor = theGeomObject->GetColor();
2005       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2006       if ( !hasColor ) {
2007 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2008         bool general_autocolor = true;
2009 #else                    // auto-color for groups only
2010         bool general_autocolor = false;
2011 #endif                   // GENERAL_AUTOCOLOR
2012         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2013           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2014           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2015 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2016             aSColor = getPredefinedUniqueColor();
2017             hasColor = true;
2018 #else                    // old algorithm  for auto-colors
2019             QList<SALOMEDS::Color> aReservedColors;
2020             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2021             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2022             if ( aMainSObject ) {
2023               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2024               for ( ; it->More(); it->Next() ) {
2025                 _PTR(SObject) aChildSObject( it->Value() );
2026                 GEOM::GEOM_Object_var aChildObject =
2027                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2028                 if ( CORBA::is_nil( aChildObject ) )
2029                   continue;
2030
2031                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2032                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2033                   aReservedColors.append( aReservedColor );
2034               }
2035             }
2036             aSColor = getUniqueColor( aReservedColors );
2037             hasColor = true;
2038 #endif                   // SIMPLE_AUTOCOLOR
2039           }
2040         }
2041       }
2042     }
2043   }
2044   return aSColor;
2045 }
2046
2047
2048 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2049                                        const bool eraseOnlyChildren) {
2050   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2051   if ( !app )
2052     return;
2053
2054   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2055   if ( !appStudy )
2056     return;
2057
2058   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2059
2060   if( !parent)
2061     return;
2062
2063   // Erase from all views
2064   QList<SALOME_View*> views;
2065   SALOME_View* view;
2066   ViewManagerList vmans = app->viewManagers();
2067   SUIT_ViewManager* vman;
2068   foreach ( vman, vmans ) {
2069     SUIT_ViewModel* vmod = vman->getViewModel();
2070     view = dynamic_cast<SALOME_View*> ( vmod );
2071     if ( view )
2072       views.append( view );
2073   }
2074
2075   if( views.count() == 0 )
2076     return;
2077
2078   //Erase childrens w/o update views
2079   DataObjectList listObj = parent->children( true );
2080   SUIT_DataObject* obj;
2081   foreach( obj, listObj ) {
2082     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2083     if(l_obj)
2084       foreach ( view, views ) {
2085       Handle(SALOME_InteractiveObject) anIO =
2086         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2087       Erase(anIO, false, false, view);
2088     }
2089   }
2090
2091   //Erase parent with view update or repaint views
2092   foreach ( view, views ) {
2093     if(!eraseOnlyChildren)
2094       Erase(theIO, false, true, view);
2095     else
2096       view->Repaint();
2097   }
2098 }