]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
21854: Add persistent dimensions
[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 #include "GEOMGUI_DimensionProperty.h"
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_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
48
49 #include <GEOMUtils.hxx>
50
51 #include <Material_Model.h>
52
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
58
59 #include <Basics_OCCTVersion.hxx>
60
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
67
68 #include <SALOME_ListIteratorOfListIO.hxx>
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
71
72 #include <SOCC_Prs.h>
73 #include <SOCC_ViewModel.h>
74
75 #include <SVTK_Prs.h>
76 #include <SVTK_ViewModel.h>
77
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
80
81 // OCCT Includes
82 #include <AIS_Drawer.hxx>
83 #include <AIS_Dimension.hxx>
84 #include <AIS_LengthDimension.hxx>
85 #include <AIS_DiameterDimension.hxx>
86 #include <AIS_AngleDimension.hxx>
87 #include <AIS_ListIteratorOfListOfInteractive.hxx>
88 #include <Aspect_PolygonOffsetMode.hxx>
89 #include <Aspect_ColorScale.hxx>
90 #include <Prs3d_IsoAspect.hxx>
91 #include <Prs3d_PointAspect.hxx>
92 #include <StdSelect_TypeOfEdge.hxx>
93 #include <StdSelect_TypeOfFace.hxx>
94 #include <StdSelect_DisplayMode.hxx>
95 #include <TopoDS_Face.hxx>
96 #include <BRep_Tool.hxx>
97 #include <Geom_Plane.hxx>
98 #include <Geom_Axis2Placement.hxx>
99 #include <Graphic3d_AspectFillArea3d.hxx>
100 #include <gp_Pln.hxx>
101 #include <TColStd_MapOfInteger.hxx>
102 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
103 #include <TopoDS_Iterator.hxx>
104 #include <Graphic3d_AspectMarker3d.hxx>
105 #include <TopTools_MapOfShape.hxx>
106 #include <TopTools_ListOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopoDS.hxx>
109
110 #include <Prs3d_ShadingAspect.hxx>
111
112 #include <BRepMesh_IncrementalMesh.hxx>
113
114 // VTK Includes
115 #include <vtkActorCollection.h>
116 #include <vtkProperty.h>
117
118 // CORBA Headers
119 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
120
121 #include <GEOMImpl_Types.hxx>
122
123 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
124 #include <TColStd_HArray1OfByte.hxx>
125 #else
126 #include <Graphic3d_HArray1OfBytes.hxx>
127 #endif
128
129 // If the next macro is defined, autocolor feature works for all sub-shapes;
130 // if it is undefined, autocolor feature works for groups only
131 #define GENERAL_AUTOCOLOR
132 // Below macro, when uncommented, switches on simplified (more performant) algorithm
133 // of auto-color picking up
134 #define SIMPLE_AUTOCOLOR
135
136 // Hard-coded value of shape deflection coefficient for VTK viewer
137 const double VTK_MIN_DEFLECTION = 0.001;
138
139 //================================================================
140 // Function : getActiveStudy
141 // Purpose  : Get active study, returns 0 if no open study frame
142 //================================================================
143 static inline SalomeApp_Study* getActiveStudy()
144 {
145   SUIT_Session* session = SUIT_Session::session();
146   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
147   if ( app )
148     return ( SalomeApp_Study* )app->activeStudy();
149   return 0;
150 }
151
152 static inline int getViewManagerId( SALOME_View* theViewFrame) {
153   SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
154   SUIT_ViewManager* aViewMgr = 0;
155   if (aModel != 0)
156     aViewMgr = aModel->getViewManager();
157   return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
158 }
159
160 //================================================================
161 // Function : getTopAbsMode
162 // Purpose  : Get TopAbs_ShapeEnum value corresponding to the
163 //            one from GEOMImpl_Types.h
164 //================================================================
165 static inline int getTopAbsMode( const int implType )
166 {
167   switch ( implType )
168   {
169     case GEOM_COMPOUND  : return TopAbs_COMPOUND;
170     case GEOM_SOLID     : return TopAbs_SOLID;
171     case GEOM_SHELL     : return TopAbs_SHELL;
172     case GEOM_FACE      : return TopAbs_FACE;
173     case GEOM_WIRE      : return TopAbs_WIRE;
174     case GEOM_EDGE      : return TopAbs_EDGE;
175     case GEOM_POINT     : return TopAbs_VERTEX;
176     default             : return -1;
177   }
178 }
179
180 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
181 {
182   if ( shape.IsNull() )
183     return TopAbs_SHAPE;
184
185   int ret = shape.ShapeType();
186
187   if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
188     TopoDS_Iterator it(shape, Standard_True, Standard_False);
189     for (; it.More(); it.Next()) {
190       TopoDS_Shape sub_shape = it.Value();
191       if ( sub_shape.IsNull() ) continue;
192       int stype = getMinMaxShapeType( sub_shape, ismin );
193       if ( stype == TopAbs_SHAPE ) continue;
194       if ( ismin && stype > ret )
195         ret = stype;
196       else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
197         ret = stype;
198     }
199   }
200
201   return ret;
202 }
203
204 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
205 {
206   return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
207 }
208
209 //================================================================
210 // Function : getFilter
211 // Purpose  : Get filter corresponding to the type of object
212 //            from GEOMImpl_Types.h
213 //================================================================
214 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
215 {
216   SUIT_SelectionFilter* aFilter;
217
218   int aTopAbsMode = getTopAbsMode( theMode );
219   if ( aTopAbsMode != -1 )
220     aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
221   else
222     switch ( theMode )
223       {
224       case GEOM_LINE      : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
225       case GEOM_CIRCLE    : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
226
227       case GEOM_PLANE     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
228       case GEOM_CYLINDER  : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
229       case GEOM_SPHERE    : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
230       case GEOM_TORUS     : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
231       case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
232       case GEOM_CONE      : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
233
234       case GEOM_PREVIEW   : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
235
236       case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
237       case GEOM_ALLGEOM   : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
238
239       default             : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
240       }
241
242   return aFilter;
243 }
244
245 //================================================================
246 // Function : getComplexFilter
247 // Purpose  : Get compound filter corresponding to the type of
248 //            object from GEOMImpl_Types.h
249 //================================================================
250 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
251 {
252   GEOM_CompoundFilter* aFilter;
253
254   if(aSubShapes != NULL ) {
255     aFilter = new GEOM_CompoundFilter(getStudy());
256     QList<int> aTopAbsTypes;
257     QList<int>::const_iterator it;
258     for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
259       int topAbsMode = getTopAbsMode(*it);
260       if(topAbsMode != -1 )
261         aTopAbsTypes.append(topAbsMode);
262     }
263     aFilter->addSubTypes(aTopAbsTypes);
264   }
265
266   return aFilter;
267 }
268
269 //================================================================
270 // Function : getEntry
271 // Purpose  :
272 //================================================================
273 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
274 {
275   SUIT_Session* session = SUIT_Session::session();
276   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
277   if ( app )
278   {
279     CORBA::String_var IOR = app->orb()->object_to_string( object );
280     if ( strcmp(IOR.in(), "") != 0 )
281     {
282       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
283       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
284       if ( SO )
285         return SO->GetID();
286     }
287   }
288   return "";
289 }
290
291 //================================================================
292 // Function : getName
293 // Purpose  :
294 //================================================================
295 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
296 {
297   SUIT_Session* session = SUIT_Session::session();
298   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
299   if ( app )
300   {
301     CORBA::String_var IOR = app->orb()->object_to_string( object );
302     if ( strcmp(IOR.in(), "") != 0 )
303     {
304       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
305       _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
306
307       _PTR(GenericAttribute) anAttr;
308
309       if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
310       {
311         _PTR(AttributeName) aNameAttr( anAttr );
312         return aNameAttr->Value();
313       }
314     }
315   }
316
317   return "";
318 }
319
320 //=================================================================
321 /*!
322  *  GEOM_Displayer::GEOM_Displayer
323  *  Constructor
324  */
325 //=================================================================
326 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
327 {
328   if( st )
329     myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
330   else
331     myApp = 0;
332
333   /* Shading Color */
334   SUIT_Session* session = SUIT_Session::session();
335   SUIT_ResourceMgr* resMgr = session->resourceMgr();
336
337   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
338   myShadingColor = SalomeApp_Tools::color( col );
339
340   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
341   myHasDisplayMode = false;
342
343   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
344   myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
345   myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
346
347   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
348   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
349   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
350
351   myColor = -1;
352   // This color is used for shape displaying. If it is equal -1 then
353   // default color is used.
354   myTexture = "";
355
356   myWidth = -1;
357   myType = -1;
358
359   myToActivate = true;
360   // This parameter is used for activisation/deactivisation of objects to be displayed
361
362   #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
363   // Activate parallel vizualisation only for testing purpose
364   // and if the corresponding env variable is set to 1
365   char* parallel_visu = getenv("PARALLEL_VISU");
366   if (parallel_visu && atoi(parallel_visu))
367   {
368     MESSAGE("Parallel visualisation on");
369     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
370   }
371   #endif
372
373   myViewFrame = 0;
374
375   myFieldDataType = GEOM::FDT_Double;
376   myFieldDimension = 0;
377   myFieldStepRangeMin = 0;
378   myFieldStepRangeMax = 0;
379 }
380
381 //=================================================================
382 /*!
383  *  GEOM_Displayer::~GEOM_Displayer
384  *  Destructor
385  */
386 //=================================================================
387 GEOM_Displayer::~GEOM_Displayer()
388 {
389 }
390
391 //=================================================================
392 /*!
393  *  GEOM_Displayer::Display
394  *  Display interactive object in the current viewer
395  */
396 //=================================================================
397 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
398                              const bool updateViewer,
399                              SALOME_View* theViewFrame )
400 {
401   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
402   if ( vf )
403   {
404     SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
405
406     if ( prs )
407     {
408       vf->BeforeDisplay( this, prs );
409       vf->Display( prs );
410       vf->AfterDisplay( this, prs );
411
412       if ( updateViewer )
413         vf->Repaint();
414
415       int aMgrId = getViewManagerId(vf);
416       SalomeApp_Study* aStudy = getStudy();
417       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
418
419       setVisibilityState(theIO->getEntry(), Qtx::ShownState);
420
421       delete prs;  // delete presentation because displayer is its owner
422     }
423   }
424 }
425
426 //=================================================================
427 /*!
428  *  GEOM_Displayer::Display
429  *  This overloaded Display() method can be useful for operations
430  *  not using dialog boxes.
431  */
432 //=================================================================
433 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
434 {
435   if ( theObj->_is_nil() )
436     return;
437
438   std::string entry = getEntry( theObj );
439   if ( entry != "" ) {
440     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
441             updateViewer);
442   }
443 }
444
445 //=================================================================
446 /*!
447  *  GEOM_Displayer::Erase
448  *  Erase interactive object in the current viewer
449  */
450 //=================================================================
451 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
452                             const bool forced,
453                             const bool updateViewer,
454                             SALOME_View* theViewFrame )
455 {
456   if ( theIO.IsNull() )
457     return;
458
459   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
460
461   if ( vf ) {
462     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
463     if ( prs ) {
464       vf->BeforeErase( this, prs );
465       vf->Erase( prs, forced );
466       vf->AfterErase( this, prs );
467       if ( updateViewer )
468         vf->Repaint();
469       delete prs;  // delete presentation because displayer is its owner
470
471       int aMgrId = getViewManagerId(vf);
472       SalomeApp_Study* aStudy = getStudy();
473       aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
474
475       setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
476     }
477   }
478 }
479
480 //=================================================================
481 /*!
482  *  GEOM_Displayer::Erase
483  *  Erase geometry object in the current viewer
484  */
485 //=================================================================
486 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
487                             const bool forced,
488                             const bool updateViewer,
489                             SALOME_View* theViewFrame)
490 {
491   std::string entry = getEntry( theObj );
492   if ( entry != "" )
493   {
494     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
495           forced, updateViewer, theViewFrame);
496   }
497 }
498
499 //=================================================================
500 /*!
501  *  GEOM_Displayer::Redisplay
502  *  Redisplay (erase and then display again) interactive object
503  *  in the current viewer
504  */
505 //=================================================================
506 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
507                                 const bool updateViewer,
508                                 const bool checkActiveViewer )
509 {
510   // Remove the object permanently (<forced> == true)
511   SUIT_Session* ses = SUIT_Session::session();
512   SUIT_Application* app = ses->activeApplication();
513   if ( app )
514   {
515     SUIT_Desktop* desk = app->desktop();
516     QList<SUIT_ViewWindow*> wnds = desk->windows();
517     SUIT_ViewWindow* wnd;
518     QListIterator<SUIT_ViewWindow*> it( wnds );
519     while ( it.hasNext() && (wnd = it.next()) )
520     {
521       SUIT_ViewManager* vman = wnd->getViewManager();
522       if ( vman )
523       {
524         SUIT_ViewModel* vmodel = vman->getViewModel();
525         if ( vmodel )
526         {
527           SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
528           if ( view )
529           {
530             if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
531             {
532               Redisplay( theIO, updateViewer, view );
533             }
534           }
535         }
536       }
537     }
538   }
539 }
540
541 //=================================================================
542 /*!
543  *  GEOM_Displayer::Redisplay
544  *  Redisplay (erase and then display again) interactive object
545  *  in the specified view
546  */
547 //=================================================================
548 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
549                                 const bool theUpdateViewer,
550                                 SALOME_View* theViewFrame )
551 {
552   SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
553   if ( !vf )
554   {
555     return;
556   }
557
558   Erase( theIO, true, false, theViewFrame );
559   Display( theIO, theUpdateViewer, theViewFrame );
560 }
561
562 //=================================================================
563 /*!
564  *  GEOM_Displayer::Display
565  *  Calls Display() method for each object in the given list
566  */
567 //=================================================================
568 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
569 {
570   SALOME_ListIteratorOfListIO Iter( theIOList );
571   for ( ; Iter.More(); Iter.Next() ) {
572     Display( Iter.Value(), false );
573   }
574   if ( updateViewer )
575     UpdateViewer();
576 }
577
578 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
579 {
580   // VSR: this method can be improved in future:
581   // to improve performance, the default values from resource manager should be cached in the displayer
582   return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
583 }
584
585 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
586 {
587   // VSR: this method can be improved in future:
588   // to improve performance, the default values from resource manager should be cached in the displayer
589   return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
590 }
591
592 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
593 {
594   // check that shape is not null
595   if ( AISShape.IsNull() ) return;
596   
597   // check that study is active
598   SalomeApp_Study* study = getStudy();
599   if ( !study ) return;
600
601   if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
602        !TopoDS_Iterator(myShape).More() )
603     return; // NPAL15983 (Bug when displaying empty groups)
604
605   // set interactive object
606
607   Handle( SALOME_InteractiveObject ) anIO;
608
609   if ( !myIO.IsNull() ) {
610     AISShape->setIO( myIO );
611     AISShape->SetOwner( myIO );
612     anIO = myIO;
613   }
614   else if ( !myName.empty() ) {
615     // workaround to allow selection of temporary objects
616     static int tempId = 0;
617     anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
618     AISShape->setIO( anIO );
619     AISShape->SetOwner( anIO );
620   }
621
622   // flag:  only vertex or compound of vertices is processed (specific handling)
623   bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
624   // presentation study entry (empty for temporary objects like preview)
625   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
626   // flag: temporary object
627   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
628   // currently active view window's ID (-1 if no active view)
629   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
630
631   // get presentation properties
632   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
633
634   // Temporary staff: vertex must be infinite for correct visualization
635   AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
636
637   // set material
638   Material_Model material;
639   // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
640   if( !HasColor() )
641     material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
642   // - set front material properties
643   AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
644   AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
645   // - set back material properties
646   AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
647   AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
648   // - switch to default (both sides) facing mode
649   AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
650
651   // set colors
652
653   // - shading color
654   if ( HasColor()  ) {
655     // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
656     // we set it to the shape not taking into account material properties
657     AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
658   }
659   else if ( !material.isPhysical() ) {
660     // shading color from properties is used only for non-physical materials
661     AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
662   }
663
664   // - wireframe color
665   Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
666   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
667                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
668   AISShape->Attributes()->SetLineAspect( anAspect );
669   
670   // - unfree boundaries color
671   anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
672   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
673                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
674   AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
675   
676   // - free boundaries color
677   anAspect = AISShape->Attributes()->FreeBoundaryAspect();
678   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
679                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
680   AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
681   
682   // - standalone edges color
683   anAspect = AISShape->Attributes()->WireAspect();
684   anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
685                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
686   AISShape->Attributes()->SetWireAspect( anAspect );
687   
688   // - color for edges in shading+edges mode
689   AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
690   
691   // ???
692   AISShape->storeBoundaryColors();
693
694   // set display mode
695   AISShape->SetDisplayMode( HasDisplayMode() ? 
696                             // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
697                             GetDisplayMode() :
698                             // display mode from properties
699                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
700
701   // set display vectors flag
702   AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
703
704   // set transparency
705   AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
706
707   // set iso properties
708   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
709   int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
710   Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
711   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
712   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
713   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
714   uIsoAspect->SetColor( isosColor );
715   uIsoAspect->SetWidth( isosWidth );
716   uIsoAspect->SetNumber( uIsos );
717   vIsoAspect->SetColor( isosColor );
718   vIsoAspect->SetWidth( isosWidth );
719   vIsoAspect->SetNumber( vIsos );
720   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
721   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
722
723   // set deflection coefficient
724   // ... to avoid to small values of the coefficient, its lower value is limited 
725   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
726
727   // set texture
728   bool textureAdded = false;
729   if ( HasTexture() ) {
730     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
731     AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
732     if ( ! entry.isEmpty() ) {
733       // check that study is active
734       SalomeApp_Study* study = getActiveStudy();
735       if ( study ) {
736         // Store the texture in object properties for next displays
737         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
738         study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
739         
740         // Update porpeties map
741         propMap = getObjectProperties( study, entry, myViewFrame );
742       }
743     }
744     textureAdded = true;
745   }
746   else {
747     // Texture from properties
748     QString aTexture = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
749     if ( !aTexture.isEmpty() ) {
750        AISShape->SetTextureFileName( TCollection_AsciiString( aTexture.toStdString().c_str() ) );
751        textureAdded = true;
752     }
753   }
754  
755   if ( textureAdded ){ 
756     AISShape->SetTextureMapOn();
757     AISShape->DisableTextureModulate();
758   }
759
760   // set line width
761   AISShape->SetWidth( HasWidth() ?
762                       // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
763                       GetWidth() :
764                       // libe width from properties
765                       propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
766
767   // set top-level flag
768   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
769
770   // set point marker (for vertex / compound of vertices only)
771   if ( onlyVertex ) {
772     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
773     if ( aList.size() == 2 ) {
774       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
775       int aTypeOfMarker = aList[0].toInt();
776       double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
777       Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
778       anAspect->SetScale( aScaleOfMarker );
779       anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
780       anAspect->SetColor( HasColor() ? 
781                           // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
782                           (Quantity_NameOfColor)GetColor() : 
783                           // color from properties
784                           SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
785       AISShape->Attributes()->SetPointAspect( anAspect );
786     }
787     else if ( aList.size() == 1 ) {
788       // custom marker string contains "IdOfTexture"
789       int textureId = aList[0].toInt();
790       Standard_Integer aWidth, aHeight;
791 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
792       Handle(TColStd_HArray1OfByte) aTexture =
793 #else
794         Handle(Graphic3d_HArray1OfBytes) aTexture =
795 #endif
796         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
797       if ( !aTexture.IsNull() ) {
798 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
799         Handle(Prs3d_PointAspect) aTextureAspect =
800           new Prs3d_PointAspect( HasColor() ? 
801                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
802                                  (Quantity_NameOfColor)GetColor() : 
803                                  // color from properties 
804                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
805                                  aWidth, aHeight,
806                                  aTexture );
807 #else
808         int TextureId = 0;
809         Handle(Prs3d_PointAspect) aTextureAspect =
810           new Prs3d_PointAspect( HasColor() ? 
811                                  // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
812                                  (Quantity_NameOfColor)GetColor() : 
813                                  // color from properties 
814                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ), 
815                                  ++TextureId,
816                                  aWidth, aHeight,
817                                  aTexture );
818 #endif
819         AISShape->Attributes()->SetPointAspect( aTextureAspect );
820       }
821     }
822   }
823
824   // set field step data
825   AISShape->setFieldStepInfo( myFieldDataType,
826                               myFieldDimension,
827                               myFieldStepData,
828                               myFieldStepName,
829                               myFieldStepRangeMin,
830                               myFieldStepRangeMax );
831
832   if ( create && !isTemporary && aMgrId != -1 ) {
833     // set properties to the study
834     study->setObjectPropMap( aMgrId, entry, propMap );
835   }
836
837   // AISShape->SetName(???); ??? necessary to set name ???
838 }
839
840 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
841 {
842   // check that actor is not null
843   if ( !actor ) return;
844   
845   // check that study is active
846   SalomeApp_Study* study = getStudy();
847   if ( !study ) return;
848
849   // set interactive object
850
851   Handle( SALOME_InteractiveObject ) anIO;
852
853   if ( !myIO.IsNull() ) {
854     actor->setIO( myIO );
855     anIO = myIO;
856   }
857   else if ( !myName.empty() ) {
858     // workaround to allow selection of temporary objects
859     static int tempId = 0;
860     anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
861     actor->setIO( anIO );
862   }
863
864   // presentation study entry (empty for temporary objects like preview)
865   QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
866   // flag: temporary object
867   bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
868   // currently active view window's ID (-1 if no active view)
869   int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
870
871   // get presentation properties
872   PropMap propMap = getObjectProperties( study, entry, myViewFrame );
873   QColor c;
874
875   /////////////////////////////////////////////////////////////////////////
876   // VSR: for VTK viewer currently deflection coefficient is hardcoded
877   //      due to performance problem
878   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
879   /////////////////////////////////////////////////////////////////////////
880   if ( !actor->getTopo().IsSame( myShape ) )
881     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
882
883   // set material
884   Material_Model material;
885   material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
886   std::vector<vtkProperty*> mprops;
887   mprops.push_back( material.getMaterialVTKProperty( true ) );
888   mprops.push_back( material.getMaterialVTKProperty( false) );
889   actor->SetMaterial( mprops );
890
891   // set iso-lines properties
892
893   // - set number of iso-lines
894   int nbIsos[2]= { 1, 1 };
895   QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
896   nbIsos[0] = isos[0].toInt();
897   nbIsos[1] = isos[1].toInt();
898   actor->SetNbIsos( nbIsos );
899
900   // - set iso-lines width
901   actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
902
903   // - set iso-lines color
904   c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
905   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
906
907   // set colors
908
909   if ( HasColor()  ) {
910     // - same color for all sub-actors
911     Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
912     actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
913   }
914   else {
915     // shading color (for non-physical materials)
916     if ( !material.isPhysical() ) {
917       c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
918       actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
919       actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
920     }
921
922     // - standalone edge color
923     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
924     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
925
926     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
927     // - shared edges color ???
928     actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
929
930     c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
931     // - free edges color ???
932     actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
933
934     // - point color
935     c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
936     actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
937   }
938
939   // - color for edges in shading+edges mode
940   c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
941   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
942
943   // set opacity
944   actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
945
946   // set line width
947   actor->SetWidth( HasWidth() ?
948                    // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
949                    GetWidth() :
950                    // libe width from properties
951                    propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
952   
953   // set display vectors flag
954   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
955
956   // set display mode
957   int displayMode = HasDisplayMode() ? 
958     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
959     GetDisplayMode() :
960     // display mode from properties
961     propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
962
963   // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
964   // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
965   // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
966   // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
967
968   if ( displayMode == 2 )
969       // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
970       // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
971     displayMode++;
972   actor->setDisplayMode( displayMode );
973
974   if ( myToActivate )
975     actor->PickableOn();
976   else
977     actor->PickableOff();
978
979   if ( create && !isTemporary && aMgrId != -1 ) {
980     // set properties to the study
981     study->setObjectPropMap( aMgrId, entry, propMap );
982   }
983 }
984
985 //=================================================================
986 /*!
987  *  GEOM_Displayer::updateDimensions
988  *  Creates or renews dimension presentation for the IO.
989  */
990 //=================================================================
991 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
992                                        SALOME_OCCPrs* thePrs,
993                                        const gp_Ax3& theShapeLCS )
994 {
995   SalomeApp_Study* aStudy = getStudy();
996   if ( !aStudy )
997   {
998     return;
999   }
1000
1001   if ( theIO.IsNull() )
1002   {
1003     return;
1004   }
1005
1006   SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1007
1008   AIS_ListOfInteractive aListOfIO;
1009
1010   anOccPrs->GetObjects( aListOfIO );
1011
1012   AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1013
1014   // remove outdated presentations of dimensions
1015   for ( ; aIterateIO.More(); aIterateIO.Next() )
1016   {
1017     const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1018     if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1019     {
1020       continue;
1021     }
1022
1023     aListOfIO.Remove( aIterateIO );
1024   }
1025
1026   // prepare dimension styling
1027   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1028
1029   QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1030   int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1031   double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1032   double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1033   bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1034   QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1035   QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1036
1037   // restore dimension presentation from saved attribute or property data
1038   AIS_ListOfInteractive aRestoredDimensions;
1039
1040   QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1041                                                   theIO->getEntry(),
1042                                                   GEOM::propertyName( GEOM::Dimensions ),
1043                                                   QVariant() );
1044
1045   GEOMGUI_DimensionProperty aRecords;
1046
1047   if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1048   {
1049     aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1050   }
1051   else
1052   {
1053     aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1054   }
1055   
1056   // create up-to-date dimension presentations
1057   for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1058   {
1059     if ( !aRecords.IsVisible( aPrsIt ) )
1060     {
1061       continue;
1062     }
1063
1064     // init dimension by type
1065     Handle(AIS_Dimension) aPrs;
1066     switch( aRecords.GetType( aPrsIt ) )
1067     {
1068       case GEOMGUI_DimensionProperty::DimensionType_Length :
1069       {
1070         Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1071         aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1072         aPrs = aLength;
1073         break;
1074       }
1075
1076       case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1077       {
1078         Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1079         aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1080         aPrs = aDiam;
1081         break;
1082       }
1083
1084       case GEOMGUI_DimensionProperty::DimensionType_Angle :
1085       {
1086         Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1087         aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1088         aPrs = anAng;
1089         break;
1090       }
1091     }
1092
1093     aPrs->SetOwner( theIO );
1094
1095     Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1096
1097     Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1098
1099     aStyle->SetCommonColor( aColor );
1100     aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1101     aStyle->MakeText3d( Standard_True );
1102     aStyle->MakeTextShaded( Standard_True );
1103     aStyle->SetExtensionSize( aFontHeight * 0.5 );
1104     aStyle->TextAspect()->SetHeight( aFontHeight );
1105     aStyle->ArrowAspect()->SetLength( anArrowLength );
1106     aStyle->LineAspect()->SetWidth( aLineWidth );
1107     aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1108     aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1109     aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1110     aPrs->SetDimensionAspect( aStyle );
1111     aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1112     aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1113     aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1114
1115     if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1116     {
1117       // show degree symbol for dimension instead of label "deg"
1118       if ( aUnitsAngle == "deg" )
1119       {
1120         aPrs->SetSpecialSymbol(0xB0);
1121         aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1122         aStyle->MakeUnitsDisplayed(Standard_False);
1123       }
1124       else
1125       {
1126         aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1127         aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1128       }
1129     }
1130     else
1131     {
1132       aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1133     }
1134
1135     aListOfIO.Append( aPrs );
1136   }
1137
1138   // update presentation
1139   anOccPrs->Clear();
1140
1141   for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1142   {
1143     anOccPrs->AddObject( aIterateIO.Value() );
1144   }
1145 }
1146
1147 //=================================================================
1148 /*!
1149  *  GEOM_Displayer::Erase
1150  *  Calls Erase() method for each object in the given list
1151  */
1152 //=================================================================
1153 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1154                             const bool forced,
1155                             const bool updateViewer )
1156 {
1157   SALOME_ListIteratorOfListIO Iter( theIOList );
1158   for ( ; Iter.More(); Iter.Next() )
1159     Erase( Iter.Value(), forced, false );
1160
1161   if ( updateViewer )
1162     UpdateViewer();
1163 }
1164
1165 //=================================================================
1166 /*!
1167  *  GEOM_Displayer::Redisplay
1168  *  Calls Redisplay() method for each object in the given list
1169  */
1170 //=================================================================
1171 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1172                                 const bool updateViewer,
1173                                 const bool checkActiveViewer )
1174 {
1175   SALOME_ListIteratorOfListIO Iter( theIOList );
1176   for ( ; Iter.More(); Iter.Next() )
1177     Redisplay( Iter.Value(), false, checkActiveViewer );
1178
1179   if ( updateViewer )
1180     UpdateViewer();
1181 }
1182
1183 //=================================================================
1184 /*!
1185  *  GEOM_Displayer::Redisplay
1186  *  Calls Redisplay() method for each object in the given list
1187  */
1188 //=================================================================
1189 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1190                                 const bool theUpdateViewer,
1191                                 SALOME_View* theViewFrame )
1192 {
1193   SALOME_ListIteratorOfListIO anIter( theIOList );
1194   for ( ; anIter.More(); anIter.Next() )
1195   {
1196     Redisplay( anIter.Value(), false, theViewFrame );
1197   }
1198
1199   if ( theUpdateViewer )
1200   {
1201     UpdateViewer();
1202   }
1203 }
1204
1205 //=================================================================
1206 /*!
1207  *  GEOM_Displayer::Update
1208  *  Update OCC presentaion
1209  *  [ Reimplemented from SALOME_Displayer ]
1210  */
1211 //=================================================================
1212 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1213 {
1214   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1215   SalomeApp_Study* study = getStudy();
1216
1217   if ( !occPrs || myShape.IsNull() || !study )
1218     return;
1219
1220   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1221   {
1222     // 
1223     // specific processing for local coordinate system presentation
1224     // 
1225
1226     TopoDS_Face aFace = TopoDS::Face( myShape );
1227     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1228     if ( !aPlane.IsNull() )
1229     {
1230       gp_Ax3 aPos = aPlane->Pln().Position();
1231       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1232
1233       Handle(GEOM_AISTrihedron) aTrh;
1234
1235       if ( occPrs->IsNull() )
1236       {
1237         // new presentation is being created
1238         aTrh = new GEOM_AISTrihedron( aPlc );
1239         occPrs->AddObject( aTrh );
1240       }
1241       else
1242       {
1243         // presentation is being updated
1244         AIS_ListOfInteractive aList;
1245         occPrs->GetObjects( aList );
1246         AIS_ListIteratorOfListOfInteractive anIter( aList );
1247         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1248           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1249         }
1250       }
1251         
1252       if ( !aTrh.IsNull() ) {
1253         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1254         if ( HasColor() )
1255           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1256         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1257         if ( HasWidth() )
1258           aTrh->SetWidth( GetWidth() );
1259         
1260         if ( !myIO.IsNull() )
1261         {
1262           aTrh->setIO( myIO );
1263           aTrh->SetOwner( myIO );
1264         }
1265         aTrh->SetComponent( aPlc );
1266         aTrh->SetToUpdate();
1267       }
1268       occPrs->SetToActivate( ToActivate() );
1269     }
1270   }
1271   else
1272   {
1273     // 
1274     // processing for usual geometry presentation
1275     // 
1276
1277     // if presentation is empty we try to create new one
1278     if ( occPrs->IsNull() )
1279     {
1280       // create presentation (specific for vectors)
1281       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1282                                                                  : new GEOM_AISShape ( myShape, "" );
1283
1284       if( myType == GEOM_FIELD_STEP )
1285         AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1286       // update shape properties
1287       updateShapeProperties( AISShape, true );
1288
1289       // add shape to the presentation
1290       occPrs->AddObject( AISShape );
1291
1292       // In accordance with ToActivate() value object will be activated/deactivated
1293       // when it will be displayed
1294       occPrs->SetToActivate( ToActivate() );
1295
1296       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1297         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1298
1299         // create additional wireframe shape
1300         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1301         aWirePrs->SetWidth(AISShape->Width());
1302         if ( !myIO.IsNull() ) {
1303           aWirePrs->setIO( myIO );
1304           aWirePrs->SetOwner( myIO );
1305         }
1306
1307         // add shape to the presentation
1308         occPrs->AddObject( aWirePrs );
1309       }
1310     }
1311     // if presentation is found -> set again shape for it
1312     else
1313     {
1314       AIS_ListOfInteractive IOList;
1315       occPrs->GetObjects( IOList );
1316       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1317       for ( ; Iter.More(); Iter.Next() )
1318       {
1319         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1320         if ( AISShape.IsNull() )
1321           continue;
1322
1323         // re-set shape (it might be changed)
1324         if ( AISShape->Shape() != myShape )
1325           AISShape->Set( myShape );
1326
1327         // update shape properties
1328         updateShapeProperties( AISShape, false );
1329
1330         // force updating
1331         AISShape->UpdateSelection();
1332         AISShape->SetToUpdate();
1333       }
1334     }
1335
1336     updateDimensions( myIO, occPrs, GEOMUtils::GetPosition( myShape ) );
1337   }
1338 }
1339
1340 //=================================================================
1341 /*!
1342  *  GEOM_Displayer::Update
1343  *  Update VTK presentaion
1344  *  [ Reimplemented from SALOME_Displayer ]
1345  */
1346 //=================================================================
1347 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1348 {
1349   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1350   SalomeApp_Study* study = getStudy();
1351
1352   if ( !vtkPrs || myShape.IsNull() || !study )
1353     return;
1354
1355   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1356   {
1357     // 
1358     // specific processing for local coordinate system presentation
1359     // 
1360
1361     TopoDS_Face aFace = TopoDS::Face( myShape );
1362     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1363     if ( !aPlane.IsNull() ) {
1364       gp_Ax3 aPos = aPlane->Pln().Position();
1365       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1366
1367       GEOM_VTKTrihedron* aTrh = 0;
1368
1369       if ( vtkPrs->IsNull() ) {
1370         // new presentation is being created
1371         aTrh = GEOM_VTKTrihedron::New();
1372         vtkPrs->AddObject( aTrh );
1373       }
1374       else {
1375         // presentation is being updated
1376         vtkActorCollection* actors = vtkPrs->GetObjects();
1377         if ( actors ) {
1378           actors->InitTraversal();
1379           vtkActor* a = actors->GetNextActor();
1380           while ( a && !aTrh ) {
1381             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1382             a = actors->GetNextActor();
1383           }
1384         }
1385       }
1386       
1387       if ( aTrh ) {
1388         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1389         if ( HasColor() ) {
1390           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1391           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1392         }
1393 #ifdef VTK_TRIHEDRON_WIDTH
1394         // 
1395         // VSR: currently isn't supported
1396         //
1397         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1398         if ( HasWidth() )
1399           aTrh->SetWidth( GetWidth() );
1400 #endif
1401
1402         if ( !myIO.IsNull() )
1403           aTrh->setIO( myIO );
1404
1405         aTrh->SetPlacement( aPlc );
1406       }
1407     }
1408   }
1409   else
1410   {
1411     // 
1412     // processing for usual geometry presentation
1413     // 
1414
1415     // if presentation is empty we try to create new one
1416     if ( vtkPrs->IsNull() )
1417     {
1418       // create an actor
1419       GEOM_Actor* actor = GEOM_Actor::New();
1420       // update actor properties
1421       updateActorProperties( actor, true );
1422       // add actor to the presentation
1423       vtkPrs->AddObject( actor );
1424     }
1425     else {
1426       // presentation is being updated
1427       vtkActorCollection* actors = vtkPrs->GetObjects();
1428       if ( actors ) {
1429         actors->InitTraversal();
1430         vtkActor* a = actors->GetNextActor();
1431         while ( a ) {
1432           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1433           if ( actor ) {
1434             // update actor properties
1435             updateActorProperties( actor, false );
1436             a = actors->GetNextActor();
1437           }
1438         }
1439       }
1440     }
1441   }
1442 }
1443
1444 //=================================================================
1445 /*!
1446  *  GEOM_Displayer::BuildPrs
1447  *  Build presentation accordint to the current viewer type
1448  */
1449 //=================================================================
1450 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1451 {
1452   if ( theObj->_is_nil() )
1453     return 0;
1454
1455   myViewFrame = GetActiveView();
1456   if ( myViewFrame == 0 )
1457     return 0;
1458
1459   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1460   if ( aPrs == 0 )
1461     return 0;
1462
1463   internalReset();
1464   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1465   myType = theObj->GetType();
1466
1467   // Update presentation
1468   UpdatePrs( aPrs );
1469
1470   return aPrs;
1471 }
1472
1473 //=================================================================
1474 /*!
1475  *  GEOM_Displayer::BuildPrs
1476  *  Build presentation accordint to the current viewer type
1477  */
1478 //=================================================================
1479 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1480 {
1481   myViewFrame = GetActiveView();
1482   if ( theShape.IsNull() || myViewFrame == 0 )
1483     return 0;
1484
1485   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1486   if ( aPrs == 0 )
1487     return 0;
1488
1489   internalReset();
1490   setShape( theShape );
1491   myType = -1;
1492
1493   UpdatePrs( aPrs );
1494
1495   return aPrs;
1496 }
1497
1498 //=================================================================
1499 /*!
1500  *  GEOM_Displayer::buildPresentation
1501  *  Builds/finds object's presentation for the current viewer
1502  *  Calls corresponding Update() method by means of double dispatch
1503  *  [ internal ]
1504  */
1505 //=================================================================
1506 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1507                                                SALOME_View* theViewFrame )
1508 {
1509   SALOME_Prs* prs = 0;
1510   internalReset();
1511
1512   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1513
1514   if ( myViewFrame )
1515   {
1516     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1517     if ( prs )
1518     {
1519       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1520       theIO->setEntry( entry.toLatin1().constData() );
1521       if ( !theIO.IsNull() )
1522       {
1523         // set interactive object
1524         setIO( theIO );
1525         //  Find SOBject (because shape should be published previously)
1526         SUIT_Session* session = SUIT_Session::session();
1527         SUIT_Application* app = session->activeApplication();
1528         if ( app )
1529         {
1530           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1531           if ( study )
1532           {
1533             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1534             if ( SO )
1535             {
1536               // get CORBA reference to data object
1537               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1538               if ( !CORBA::is_nil( object ) )
1539               {
1540                 // downcast to GEOM base object
1541                 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1542                 if ( !GeomBaseObject->_is_nil() )
1543                 {
1544                   myType = GeomBaseObject->GetType();
1545
1546                   // downcast to GEOM object
1547                   GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1548                   if ( myType == GEOM_FIELD_STEP )
1549                   {
1550                     // get the GEOM object from the field's shape
1551                     GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1552                     if ( !GeomFieldStep->_is_nil() )
1553                     {
1554                       GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1555                       if ( !GeomField->_is_nil() )
1556                         GeomObject = GeomField->GetShape();
1557                     }
1558
1559                     // read the field step information
1560                     readFieldStepInfo( GeomFieldStep );
1561                   }
1562
1563                   if ( !GeomObject->_is_nil() )
1564                   {
1565                     // finally set shape
1566                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1567                   }
1568                 }
1569               }
1570             }
1571           }
1572         }
1573       }
1574       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1575     }
1576   }
1577   return prs;
1578 }
1579
1580 //=================================================================
1581 /*!
1582  *  GEOM_Displayer::buildSubshapePresentation
1583  *  Builds/finds object's presentation for the current viewer
1584  *  Calls corresponding Update() method by means of double dispatch
1585  *  For not published objects (for Mantis issue 0020435)
1586  */
1587 //=================================================================
1588 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1589                                                       const QString& entry,
1590                                                       SALOME_View* theViewFrame)
1591 {
1592   SALOME_Prs* prs = 0;
1593   internalReset();
1594
1595   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1596
1597   if (myViewFrame)
1598   {
1599     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1600     if (prs)
1601     {
1602       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1603       theIO->setEntry(entry.toLatin1().constData());
1604       if (!theIO.IsNull())
1605       {
1606         // set interactive object
1607         setIO(theIO);
1608         // finally set shape
1609         setShape(aShape);
1610         myType = GEOM_SUBSHAPE;
1611       }
1612       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1613     }
1614   }
1615   return prs;
1616 }
1617
1618 //=================================================================
1619 /*!
1620  *  GEOM_Displayer::internalReset
1621  *  Resets internal data
1622  *  [internal]
1623  */
1624 //=================================================================
1625 void GEOM_Displayer::internalReset()
1626 {
1627   myIO.Nullify();
1628   myShape.Nullify();
1629
1630   myFieldDataType = GEOM::FDT_Double;
1631   myFieldDimension = 0;
1632   myFieldStepData.clear();
1633   myFieldStepName.Clear();
1634   myFieldStepRangeMin = 0;
1635   myFieldStepRangeMax = 0;
1636 }
1637
1638 //=================================================================
1639 /*!
1640  *  GEOM_Displayer::LocalSelection
1641  *  Activate selection of CAD shapes with activisation of selection
1642  *  of their sub-shapes (with opened local context for OCC viewer)
1643  */
1644 //=================================================================
1645 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1646 {
1647   SUIT_Session* session = SUIT_Session::session();
1648   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1649   if ( !app )
1650     return;
1651
1652   LightApp_SelectionMgr* sm = app->selectionMgr();
1653
1654   // remove all filters from selection
1655   sm->clearFilters();
1656
1657   SALOME_View* vf = GetActiveView();
1658   if ( vf ) {
1659     if (!theIO.IsNull() && !vf->isVisible(theIO))
1660       Display(theIO);
1661     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1662     vf->LocalSelection( prs, theMode );
1663     delete prs;  // delete presentation because displayer is its owner
1664   }
1665 }
1666
1667 //=================================================================
1668 /*!
1669  *  GEOM_Displayer::globalSelection
1670  *  Activate selection of CAD shapes without activisation of selection
1671  *  of their sub-shapes (without opened local context for OCC viewer)
1672  */
1673 //=================================================================
1674 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1675 {
1676   TColStd_MapOfInteger aModes;
1677   aModes.Add( theMode );
1678   GlobalSelection( aModes, update );
1679 }
1680
1681 //=================================================================
1682 /*!
1683  *  GEOM_Displayer::globalSelection
1684  *  Activate selection of CAD shapes without activisation of selection
1685  *  of their sub-shapes (without opened local context for OCC viewer)
1686  */
1687 //=================================================================
1688 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1689                                       const bool update, const QList<int>* theSubShapes )
1690 {
1691   SUIT_Session* session = SUIT_Session::session();
1692   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1693   if ( !app )
1694     return;
1695
1696   SALOME_View* vf = GetActiveView();
1697   if ( vf == 0 )
1698     return;
1699
1700   // Close local context
1701   vf->GlobalSelection( update );
1702
1703   // Set selection filters in accordance with current mode
1704   LightApp_SelectionMgr* sm = app->selectionMgr();
1705   if ( !sm )
1706     return;
1707
1708   // Remove from selection temporary objects if necessary
1709   if ( !theModes.Contains( GEOM_PREVIEW ) )
1710     clearTemporary( sm );
1711
1712   //@ aSel->ClearIndex();
1713
1714   sm->clearFilters();
1715
1716   // Remove filters from AIS_InteractiveContext
1717   Handle(AIS_InteractiveContext) ic;
1718   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1719   if ( viewer )
1720     {
1721       ic = viewer->getAISContext();
1722       if ( !ic.IsNull() )
1723         ic->RemoveFilters();
1724     }
1725
1726   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1727     return;
1728
1729   SUIT_SelectionFilter* aFilter;
1730   if ( theModes.Extent() == 1 )
1731     {
1732       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1733
1734       if ( aMode == GEOM_COMPOUNDFILTER )
1735         aFilter = getComplexFilter( theSubShapes );
1736       else
1737         aFilter = getFilter( aMode );
1738     }
1739   else if ( theModes.Extent() > 1 )
1740     {
1741       TColStd_MapOfInteger aTopAbsModes;
1742       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1743       QList<SUIT_SelectionFilter*> aListOfFilters;
1744       for ( ; anIter.More(); anIter.Next() )
1745         {
1746           SUIT_SelectionFilter* aFilter;
1747           int aMode = anIter.Key();
1748           if ( aMode == GEOM_COMPOUNDFILTER )
1749             aFilter = getComplexFilter( theSubShapes );
1750           else
1751             aFilter = getFilter( aMode );
1752
1753           if ( aFilter )
1754             aListOfFilters.append( aFilter );
1755         }
1756
1757       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1758     }
1759   else
1760     return;
1761
1762   if ( aFilter )
1763     {
1764       sm->installFilter( aFilter );
1765       if ( !ic.IsNull() )
1766         {
1767           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1768           ic->AddFilter( anOCCFilter );
1769         }
1770     }
1771 }
1772
1773 //=================================================================
1774 /*!
1775  *  GEOM_Displayer::LocalSelection
1776  *  Activate selection of CAD shapes with activisation of selection
1777  *  of their sub-shapes (with opened local context for OCC viewer)
1778  */
1779 //=================================================================
1780 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1781 {
1782   SALOME_ListIteratorOfListIO Iter( theIOList );
1783   for ( ; Iter.More(); Iter.Next() )
1784     LocalSelection( Iter.Value(), theMode );
1785 }
1786
1787 //=================================================================
1788 /*!
1789  *  GEOM_Displayer::BeforeDisplay
1790  *  Called before displaying of pars. Close local context
1791  *  [ Reimplemented from SALOME_Displayer ]
1792  */
1793 //=================================================================
1794 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1795 {
1796   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1797   if ( vf )
1798   {
1799     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1800     if ( !ic.IsNull() )
1801     {
1802       if ( ic->HasOpenedContext() )
1803       ic->CloseAllContexts();
1804     }
1805   }
1806 }
1807
1808 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1809 {
1810   UpdateColorScale(false,false);
1811 }
1812
1813 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1814 {
1815   LightApp_Displayer::AfterErase( v, p );
1816   UpdateColorScale(false,false);
1817 }
1818
1819 //=================================================================
1820 /*!
1821  *  GEOM_Displayer::SetColor
1822  *  Set color for shape displaying. If it is equal -1 then default color is used.
1823  *  Available values are from Quantity_NameOfColor enumeration
1824  */
1825 //=================================================================
1826 void GEOM_Displayer::SetColor( const int color )
1827 {
1828   if ( color == -1 )
1829     UnsetColor();
1830   else
1831   {
1832     myColor = color;
1833     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1834   }
1835 }
1836
1837 int GEOM_Displayer::GetColor() const
1838 {
1839   return myColor;
1840 }
1841
1842 bool GEOM_Displayer::HasColor() const
1843 {
1844   return myColor != -1;
1845 }
1846
1847 void GEOM_Displayer::UnsetColor()
1848 {
1849   myColor = -1;
1850
1851   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1852   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1853   myShadingColor = SalomeApp_Tools::color( col );
1854 }
1855
1856 //=================================================================
1857 /*!
1858  *  GEOM_Displayer::SetTexture
1859  *  Set color for shape displaying. If it is equal -1 then default color is used.
1860  *  Available values are from Quantity_NameOfColor enumeration
1861  */
1862 //=================================================================
1863 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1864 {
1865   if(texureFileName!="")
1866   {
1867     myTexture = texureFileName;
1868   }
1869 }
1870
1871 bool GEOM_Displayer::HasTexture() const
1872 {
1873   return myTexture != "";
1874 }
1875
1876 std::string GEOM_Displayer::GetTexture() const
1877 {
1878   return myTexture;
1879 }
1880
1881 //=================================================================
1882 /*!
1883  *  GEOM_Displayer::SetWidth
1884  *  Set width of shape displaying. If it is equal -1 then default width is used.
1885  */
1886 //=================================================================
1887 void GEOM_Displayer::SetWidth( const double width )
1888 {
1889   myWidth = width;
1890 }
1891
1892 double GEOM_Displayer::GetWidth() const
1893 {
1894   return myWidth;
1895 }
1896
1897 bool GEOM_Displayer::HasWidth() const
1898 {
1899   return myWidth != -1;
1900 }
1901
1902 void GEOM_Displayer::UnsetWidth()
1903 {
1904   myWidth = -1;
1905 }
1906
1907
1908 int GEOM_Displayer::GetIsosWidth() const
1909 {
1910   return myIsosWidth;
1911 }
1912
1913 void GEOM_Displayer::SetIsosWidth(const int width)
1914 {
1915   myIsosWidth = width;
1916 }
1917
1918 bool GEOM_Displayer::HasIsosWidth() const
1919 {
1920   return myIsosWidth != -1;
1921 }
1922
1923
1924 //=================================================================
1925 /*!
1926  *  GEOM_Displayer::SetToActivate
1927  *  This method is used for activisation/deactivisation of objects to be displayed
1928  */
1929 //=================================================================
1930 void GEOM_Displayer::SetToActivate( const bool toActivate )
1931 {
1932   myToActivate = toActivate;
1933 }
1934 bool GEOM_Displayer::ToActivate() const
1935 {
1936   return myToActivate;
1937 }
1938
1939 //=================================================================
1940 /*!
1941  *  GEOM_Displayer::clearTemporary
1942  *  Removes from selection temporary objects
1943  */
1944 //=================================================================
1945 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1946 {
1947   SALOME_ListIO selected, toSelect;
1948   theSelMgr->selectedObjects( selected );
1949
1950   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1951     Handle(SALOME_InteractiveObject) io = it.Value();
1952     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1953       toSelect.Append( it.Value() );
1954   }
1955
1956   theSelMgr->setSelectedObjects( toSelect, true );
1957 }
1958
1959 void GEOM_Displayer::SetName( const char* theName )
1960 {
1961   myName = theName;
1962 }
1963
1964 void GEOM_Displayer::UnsetName()
1965 {
1966   myName = "";
1967 }
1968
1969 SalomeApp_Study* GEOM_Displayer::getStudy() const
1970 {
1971   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1972 }
1973
1974 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1975 {
1976   myIO = theIO;
1977 }
1978
1979 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1980 {
1981   myShape = theShape;
1982 }
1983
1984 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
1985                                        const int theFieldDimension,
1986                                        const QList<QVariant>& theFieldStepData,
1987                                        const TCollection_AsciiString& theFieldStepName,
1988                                        const double theFieldStepRangeMin,
1989                                        const double theFieldStepRangeMax )
1990 {
1991   myFieldDataType = theFieldDataType;
1992   myFieldDimension = theFieldDimension;
1993   myFieldStepData = theFieldStepData;
1994   myFieldStepName = theFieldStepName;
1995   myFieldStepRangeMin = theFieldStepRangeMin;
1996   myFieldStepRangeMax = theFieldStepRangeMax;
1997 }
1998
1999 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2000 {
2001   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2002   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2003   GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2004   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2005   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2006          (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2007 }
2008
2009 int GEOM_Displayer::SetDisplayMode( const int theMode )
2010 {
2011   int aPrevMode = myDisplayMode;
2012   if ( theMode != -1 ) {
2013     myDisplayMode = theMode;
2014     myHasDisplayMode = true;
2015   }
2016   else {
2017     UnsetDisplayMode();
2018   }
2019   return aPrevMode;
2020 }
2021
2022 int GEOM_Displayer::GetDisplayMode() const
2023 {
2024   return myDisplayMode;
2025 }
2026
2027 int GEOM_Displayer::UnsetDisplayMode()
2028 {
2029   int aPrevMode = myDisplayMode;
2030   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2031   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2032   myHasDisplayMode = false;
2033   return aPrevMode;
2034 }
2035
2036 bool GEOM_Displayer::HasDisplayMode() const
2037 {
2038   return myHasDisplayMode;
2039 }
2040
2041 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2042 {
2043   static QList<QColor> colors;
2044
2045   if ( colors.isEmpty() ) {
2046
2047     for (int s = 0; s < 2 ; s++)
2048     {
2049       for (int v = 100; v >= 40; v = v - 20)
2050       {
2051         for (int h = 0; h < 359 ; h = h + 60)
2052         {
2053           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2054         }
2055       }
2056     }
2057   }
2058
2059   static int currentColor = 0;
2060
2061   SALOMEDS::Color color;
2062   color.R = (double)colors[currentColor].red()   / 255.0;
2063   color.G = (double)colors[currentColor].green() / 255.0;
2064   color.B = (double)colors[currentColor].blue()  / 255.0;
2065
2066   currentColor = (currentColor+1) % colors.count();
2067
2068   return color;
2069 }
2070
2071 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2072 {
2073   int aHue = -1;
2074   int aTolerance = 64;
2075   int anIterations = 0;
2076   int aPeriod = 5;
2077
2078   while( 1 )
2079   {
2080     anIterations++;
2081     if( anIterations % aPeriod == 0 )
2082     {
2083       aTolerance /= 2;
2084       if( aTolerance < 1 )
2085         break;
2086     }
2087     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2088
2089     aHue = (int)( 360.0 * rand() / RAND_MAX );
2090     //std::cout << "Hue = " << aHue << std::endl;
2091
2092     //std::cout << "Auto colors : ";
2093     bool ok = true;
2094     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2095     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2096     for( ; it != itEnd; ++it )
2097     {
2098       SALOMEDS::Color anAutoColor = *it;
2099       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2100
2101       int h, s, v;
2102       aQColor.getHsv( &h, &s, &v );
2103       //std::cout << h << " ";
2104       if( abs( h - aHue ) < aTolerance )
2105       {
2106         ok = false;
2107         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2108         break;
2109       }
2110     }
2111     //std::cout << std::endl;
2112
2113     if( ok )
2114       break;
2115   }
2116
2117   //std::cout << "Hue of the returned color = " << aHue << std::endl;
2118   QColor aColor;
2119   aColor.setHsv( aHue, 255, 255 );
2120
2121   SALOMEDS::Color aSColor;
2122   aSColor.R = (double)aColor.red() / 255.0;
2123   aSColor.G = (double)aColor.green() / 255.0;
2124   aSColor.B = (double)aColor.blue() / 255.0;
2125
2126   return aSColor;
2127 }
2128
2129 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2130                                              const QString& entry,
2131                                              SALOME_View* view )
2132 {
2133   // get default properties for the explicitly specified default view type
2134   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2135
2136   if ( study && view ) {
2137     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2138     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2139     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2140   
2141     if ( viewModel && viewId != -1 ) {
2142       // get properties from the study
2143       PropMap storedMap = study->getObjectPropMap( viewId, entry );
2144       // overwrite default properties from stored ones (that are specified)
2145       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2146         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2147           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
2148                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2149       }
2150       // ... specific processing for color
2151       // ... current implementation is to use same stored color for all aspects
2152       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2153       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2154         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2155         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2156         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2157         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2158         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2159       }
2160
2161       if ( !entry.isEmpty() ) {
2162         // get CORBA reference to geom object
2163         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2164         if ( SO ) {
2165           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2166           if ( !CORBA::is_nil( object ) ) {
2167             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2168             if ( !CORBA::is_nil( geomObject ) ) { // to check
2169               // check that geom object has color properly set
2170               bool hasColor = false;
2171               SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2172               // set color from geometry object (only once, if it is not yet set in GUI)
2173               // current implementation is to use same color for all aspects
2174               // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2175               if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2176                 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2177                 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
2178                 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2179                 propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
2180                 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
2181                 propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
2182               }
2183               // check that object has point marker properly set
2184               GEOM::marker_type mType = geomObject->GetMarkerType();
2185               GEOM::marker_size mSize = geomObject->GetMarkerSize();
2186               int mTextureId = geomObject->GetMarkerTexture();
2187               bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
2188                                ( mType == GEOM::MT_USER && mTextureId > 0 );
2189               // set point marker from geometry object (only once, if it is not yet set in GUI)
2190               if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2191                 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2192                   // standard type
2193                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2194                                   QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2195                 }
2196                 else if ( mType == GEOM::MT_USER ) {
2197                   // custom texture
2198                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2199                 }
2200               }
2201             }
2202           }
2203         }
2204       }
2205     }
2206   }
2207   return propMap;
2208 }
2209
2210 PropMap GEOM_Displayer::getDefaultPropertyMap()
2211 {
2212   PropMap propMap;
2213
2214   // get resource manager
2215   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2216
2217   // fill in the properties map with default values
2218
2219   // - visibility (false by default)
2220   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2221
2222   // - nb isos (take default value from preferences)
2223   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2224                   QString( "%1%2%3" ).
2225                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2226                   arg( GEOM::subSectionSeparator() ).
2227                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2228
2229   // - transparency (opacity = 1-transparency)
2230   propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2231
2232   // - display mode (take default value from preferences)
2233   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2234                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2235
2236   // - show edges direction flag (false by default)
2237   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2238
2239   // - shading color (take default value from preferences)
2240   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2241                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2242
2243   // - wireframe color (take default value from preferences)
2244   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2245                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2246
2247   // - standalone edges color (take default value from preferences)
2248   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2249                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2250
2251   // - free boundaries color (take default value from preferences)
2252   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2253                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2254
2255   // - points color (take default value from preferences)
2256   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2257                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2258
2259   // - isos color (take default value from preferences)
2260   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2261                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2262
2263   // - outlines color (take default value from preferences)
2264   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2265                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2266
2267   // - deflection coefficient (take default value from preferences)
2268   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2269                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2270
2271   // - material (take default value from preferences)
2272   Material_Model material;
2273   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2274   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2275
2276   // - edge width (take default value from preferences)
2277   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2278                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2279
2280   // - isos width (take default value from preferences)
2281   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2282                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2283
2284   // - point marker (take default value from preferences)
2285   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2286                   QString( "%1%2%3" ).
2287                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2288                   arg( GEOM::subSectionSeparator() ).
2289                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2290
2291   // - top-level flag (false by default)
2292   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2293
2294   return propMap;
2295 }
2296
2297 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2298   SALOMEDS::Color aSColor;
2299   hasColor = false;
2300
2301   SUIT_Session* session = SUIT_Session::session();
2302   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2303
2304   if ( app && !theGeomObject->_is_nil()) {
2305     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2306
2307     if ( study ) {
2308       _PTR(Study) aStudy = study->studyDS();
2309       aSColor = theGeomObject->GetColor();
2310       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2311       if ( !hasColor ) {
2312 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2313         bool general_autocolor = true;
2314 #else                    // auto-color for groups only
2315         bool general_autocolor = false;
2316 #endif                   // GENERAL_AUTOCOLOR
2317         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2318           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2319           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2320 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2321             aSColor = getPredefinedUniqueColor();
2322             hasColor = true;
2323 #else                    // old algorithm  for auto-colors
2324             QList<SALOMEDS::Color> aReservedColors;
2325             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2326             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2327             if ( aMainSObject ) {
2328               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2329               for ( ; it->More(); it->Next() ) {
2330                 _PTR(SObject) aChildSObject( it->Value() );
2331                 GEOM::GEOM_Object_var aChildObject =
2332                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2333                 if ( CORBA::is_nil( aChildObject ) )
2334                   continue;
2335
2336                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2337                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2338                   aReservedColors.append( aReservedColor );
2339               }
2340             }
2341             aSColor = getUniqueColor( aReservedColors );
2342             hasColor = true;
2343 #endif                   // SIMPLE_AUTOCOLOR
2344           }
2345         }
2346       }
2347     }
2348   }
2349   return aSColor;
2350 }
2351
2352
2353 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2354                                        const bool eraseOnlyChildren) {
2355   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2356   if ( !app )
2357     return;
2358
2359   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2360   if ( !appStudy )
2361     return;
2362
2363   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2364
2365   if( !parent)
2366     return;
2367
2368   // Erase from all views
2369   QList<SALOME_View*> views;
2370   SALOME_View* view;
2371   ViewManagerList vmans = app->viewManagers();
2372   SUIT_ViewManager* vman;
2373   foreach ( vman, vmans ) {
2374     SUIT_ViewModel* vmod = vman->getViewModel();
2375     view = dynamic_cast<SALOME_View*> ( vmod );
2376     if ( view )
2377       views.append( view );
2378   }
2379
2380   if( views.count() == 0 )
2381     return;
2382
2383   //Erase childrens w/o update views
2384   DataObjectList listObj = parent->children( true );
2385   SUIT_DataObject* obj;
2386   foreach( obj, listObj ) {
2387     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2388     if(l_obj)
2389       foreach ( view, views ) {
2390       Handle(SALOME_InteractiveObject) anIO =
2391         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2392       Erase(anIO, false, false, view);
2393     }
2394   }
2395
2396   //Erase parent with view update or repaint views
2397   foreach ( view, views ) {
2398     if(!eraseOnlyChildren)
2399       Erase(theIO, false, true, view);
2400     else
2401       view->Repaint();
2402   }
2403 }
2404
2405 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2406 {
2407   if( theGeomFieldStep->_is_nil() )
2408     return;
2409
2410   GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2411   if( aGeomField->_is_nil() )
2412     return;
2413
2414   GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2415   if( aGeomFieldShape->_is_nil() )
2416     return;
2417
2418   TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2419   TCollection_AsciiString aFieldName( aGeomField->GetName() );
2420   TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2421
2422   aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2423
2424   GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2425
2426   int aFieldDimension = aGeomField->GetDimension();
2427
2428   GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2429   int aFieldNbComponents = aFieldComponents->length();
2430
2431   QList<QVariant> aFieldStepData;
2432   if( aFieldDataType == GEOM::FDT_Bool )
2433   {
2434     GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2435     if ( !aGeomBoolFieldStep->_is_nil() )
2436     {
2437       GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2438       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2439         aFieldStepData << (bool)aValues[i];
2440     }
2441   }
2442   else if( aFieldDataType == GEOM::FDT_Int )
2443   {
2444     GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2445     if ( !aGeomIntFieldStep->_is_nil() )
2446     {
2447       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2448       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2449         aFieldStepData << (qlonglong)aValues[i];
2450     }
2451   }
2452   else if( aFieldDataType == GEOM::FDT_Double )
2453   {
2454     GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2455     if ( !aGeomDoubleFieldStep->_is_nil() )
2456     {
2457       GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2458       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2459         aFieldStepData << (double)aValues[i];
2460     }
2461   }
2462   else if( aFieldDataType == GEOM::FDT_String )
2463   {
2464     GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2465     if ( !aGeomStringFieldStep->_is_nil() )
2466     {
2467       GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2468       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2469         aFieldStepData << QString( aValues[i] );
2470     }
2471   }
2472
2473   double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2474   aFieldStepData = groupFieldData( aFieldStepData,
2475                                    aFieldNbComponents,
2476                                    aFieldDataType == GEOM::FDT_String,
2477                                    aFieldStepRangeMin,
2478                                    aFieldStepRangeMax );
2479
2480   setFieldStepInfo( aFieldDataType,
2481                     aFieldDimension,
2482                     aFieldStepData,
2483                     aFieldStepName,
2484                     aFieldStepRangeMin,
2485                     aFieldStepRangeMax );
2486 }
2487
2488 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2489                                                 const int theFieldNbComponents,
2490                                                 const bool theIsString,
2491                                                 double& theFieldStepRangeMin,
2492                                                 double& theFieldStepRangeMax )
2493 {
2494   QList<QVariant> aResultList;
2495   theFieldStepRangeMin = 0;
2496   theFieldStepRangeMax = 0;
2497
2498   if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2499     return aResultList;
2500
2501   int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2502
2503   QList<QVariant> aGroupedList;
2504
2505   bool anIsBoolean = false;
2506   for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2507   {
2508     double aNorm = 0;
2509     QStringList aStringList;
2510
2511     int aBaseIndex = aSubShape * theFieldNbComponents;
2512     for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2513     {
2514       int anIndex = aComponent + aBaseIndex;
2515
2516       const QVariant& aVariant = theFieldStepData[ anIndex ];
2517       if( theIsString )
2518       {
2519         if( aVariant.type() == QVariant::String )
2520           aStringList << aVariant.toString();
2521       }
2522       else
2523       {
2524         double aValue = 0;
2525         if( aVariant.type() == QVariant::Bool )
2526         {
2527           aValue = aVariant.toBool() ? 1.0 : 0.0;
2528           aNorm += aValue;
2529           anIsBoolean = true;
2530         }
2531         else
2532         {
2533           if( aVariant.type() == QVariant::Int )
2534             aValue = double( aVariant.toInt() );
2535           else if( aVariant.type() == QVariant::Double )
2536             aValue = aVariant.toDouble();
2537           aNorm += aValue * aValue;
2538         }
2539       }
2540     }
2541
2542     if( theIsString )
2543       aGroupedList << aStringList.join( "\n" );
2544     else
2545     {
2546       if( anIsBoolean )
2547         aNorm /= theFieldNbComponents;
2548       else
2549         aNorm = pow( aNorm, 0.5 );
2550
2551       if( aGroupedList.isEmpty() )
2552         theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2553       else
2554       {
2555         theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2556         theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2557       }
2558
2559       aGroupedList << aNorm;
2560     }
2561   }
2562
2563   if( anIsBoolean )
2564   {
2565     theFieldStepRangeMin = 0.0;
2566     theFieldStepRangeMax = 1.0;
2567   }
2568
2569   SUIT_Session* session = SUIT_Session::session();
2570   SUIT_ResourceMgr* resMgr = session->resourceMgr();
2571   Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2572
2573   QListIterator<QVariant> anIter( aGroupedList );
2574   while( anIter.hasNext() )
2575   {
2576     const QVariant& aVariant = anIter.next();
2577     if( theIsString )
2578       aResultList << aVariant;
2579     else
2580     {
2581       QColor aQColor;
2582       Quantity_Color aColor;
2583       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2584         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2585       aResultList << aQColor;
2586     }
2587   }
2588   return aResultList;
2589 }
2590
2591 // Note: the method is copied from Aspect_ColorScale class
2592 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2593                                                const Standard_Integer aMin,
2594                                                const Standard_Integer aMax )
2595 {
2596   Standard_Integer minLimit( 0 ), maxLimit( 230 );
2597
2598   Standard_Integer aHue = maxLimit;
2599   if ( aMin != aMax )
2600     aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2601
2602   aHue = Min( Max( minLimit, aHue ), maxLimit );
2603
2604   return aHue;
2605 }
2606
2607 // Note: the method is copied from Aspect_ColorScale class
2608 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
2609                                             const Standard_Real aMin,
2610                                             const Standard_Real aMax,
2611                                             const Standard_Integer ColorsCount,
2612                                             Quantity_Color& aColor )
2613 {
2614   if( aValue<aMin || aValue>aMax || aMax<aMin )
2615     return Standard_False;
2616
2617   else
2618   {
2619     Standard_Real IntervNumber = 0;
2620     if( aValue<aMin )
2621       IntervNumber = 0;
2622     else if( aValue>aMax )
2623       IntervNumber = ColorsCount-1;
2624     else if( Abs( aMax-aMin ) > Precision::Approximation() )
2625       IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2626
2627     Standard_Integer Interv = Standard_Integer( IntervNumber );
2628
2629     aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2630
2631     return Standard_True;
2632   } 
2633 }
2634
2635 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
2636 {
2637   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2638   if( !aStudy )
2639     return;
2640
2641   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2642   if( !aViewModel )
2643     return;
2644
2645   Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2646   if( aViewer.IsNull() )
2647     return;
2648
2649   aViewer->InitActiveViews();
2650   if( !aViewer->MoreActiveViews() )
2651     return;
2652
2653   Handle(V3d_View) aView = aViewer->ActiveView();
2654   if( aView.IsNull() )
2655     return;
2656
2657   Standard_Boolean anIsDisplayColorScale = Standard_False;
2658   TCollection_AsciiString aColorScaleTitle;
2659   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2660   Standard_Boolean anIsBoolean = Standard_False;
2661
2662   SALOME_ListIO aSelectedObjects;
2663   myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2664   if( aSelectedObjects.Extent() == 1 )
2665   {
2666     Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2667     if( !anIO.IsNull() )
2668     {
2669       SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2670       if( aPrs )
2671       {
2672         AIS_ListOfInteractive aList;
2673         aPrs->GetObjects( aList );
2674         AIS_ListIteratorOfListOfInteractive anIter( aList );
2675         for( ; anIter.More(); anIter.Next() )
2676         {
2677           Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2678           if( !aShape.IsNull() )
2679           {
2680             GEOM::field_data_type aFieldDataType;
2681             int aFieldDimension;
2682             QList<QVariant> aFieldStepData;
2683             TCollection_AsciiString aFieldStepName;
2684             double aFieldStepRangeMin, aFieldStepRangeMax;
2685             aShape->getFieldStepInfo( aFieldDataType,
2686                                       aFieldDimension,
2687                                       aFieldStepData,
2688                                       aFieldStepName,
2689                                       aFieldStepRangeMin,
2690                                       aFieldStepRangeMax );
2691             if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2692             {
2693               anIsDisplayColorScale = Standard_True;
2694               aColorScaleTitle = aFieldStepName;
2695               aColorScaleMin = aFieldStepRangeMin;
2696               aColorScaleMax = aFieldStepRangeMax;
2697               anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2698             }
2699           }
2700         }
2701       }
2702     }
2703   }
2704
2705   if( anIsDisplayColorScale )
2706   {
2707     Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2708     if( !aColorScale.IsNull() )
2709     {
2710       SUIT_Session* session = SUIT_Session::session();
2711       SUIT_ResourceMgr* resMgr = session->resourceMgr();
2712
2713       Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2714       Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2715       Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2716       Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2717       Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2718       Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2719  
2720       aColorScale->SetXPosition( anXPos );
2721       aColorScale->SetYPosition( anYPos );
2722       aColorScale->SetWidth( aWidth );
2723       aColorScale->SetHeight( aHeight );
2724
2725       aColorScale->SetTextHeight( aTextHeight );
2726       aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2727
2728       aColorScale->SetTitle( aColorScaleTitle );
2729       aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2730     }
2731     if( !aView->ColorScaleIsDisplayed() )
2732       aView->ColorScaleDisplay();
2733   }
2734   else
2735   {
2736     if( aView->ColorScaleIsDisplayed() )
2737       aView->ColorScaleErase();
2738   }
2739
2740   if( theIsRedisplayFieldSteps )
2741   {
2742     _PTR(Study) aStudyDS = aStudy->studyDS();
2743     QList<SUIT_ViewManager*> vmList;
2744     myApp->viewManagers( vmList );
2745     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2746     {
2747       if( SUIT_ViewManager* aViewManager = *vmIt )
2748       {
2749         const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2750         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2751         {
2752           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2753           if( aSObj )
2754           {
2755             CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2756             if( !CORBA::is_nil( anObject ) )
2757             {
2758               GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2759               if( !aFieldStep->_is_nil() )
2760               {
2761                 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2762                 Handle(SALOME_InteractiveObject) aStepIO =
2763                   new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2764                 Redisplay( aStepIO, false, false );
2765               }
2766             }
2767           }
2768         }
2769       }
2770     }
2771   }
2772   if(updateViewer)
2773     UpdateViewer();
2774 }