]> 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     aPrs->SetDimensionAspect( aStyle );
1110     aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1111     aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1112     aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1113
1114     if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1115     {
1116       // show degree symbol for dimension instead of label "deg"
1117       if ( aUnitsAngle == "deg" )
1118       {
1119         aPrs->SetSpecialSymbol(0xB0);
1120         aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1121         aStyle->MakeUnitsDisplayed(Standard_False);
1122       }
1123       else
1124       {
1125         aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1126         aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1127       }
1128     }
1129     else
1130     {
1131       aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1132     }
1133
1134     aListOfIO.Append( aPrs );
1135   }
1136
1137   // update presentation
1138   anOccPrs->Clear();
1139
1140   for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1141   {
1142     anOccPrs->AddObject( aIterateIO.Value() );
1143   }
1144 }
1145
1146 //=================================================================
1147 /*!
1148  *  GEOM_Displayer::Erase
1149  *  Calls Erase() method for each object in the given list
1150  */
1151 //=================================================================
1152 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1153                             const bool forced,
1154                             const bool updateViewer )
1155 {
1156   SALOME_ListIteratorOfListIO Iter( theIOList );
1157   for ( ; Iter.More(); Iter.Next() )
1158     Erase( Iter.Value(), forced, false );
1159
1160   if ( updateViewer )
1161     UpdateViewer();
1162 }
1163
1164 //=================================================================
1165 /*!
1166  *  GEOM_Displayer::Redisplay
1167  *  Calls Redisplay() method for each object in the given list
1168  */
1169 //=================================================================
1170 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1171                                 const bool updateViewer,
1172                                 const bool checkActiveViewer )
1173 {
1174   SALOME_ListIteratorOfListIO Iter( theIOList );
1175   for ( ; Iter.More(); Iter.Next() )
1176     Redisplay( Iter.Value(), false, checkActiveViewer );
1177
1178   if ( updateViewer )
1179     UpdateViewer();
1180 }
1181
1182 //=================================================================
1183 /*!
1184  *  GEOM_Displayer::Redisplay
1185  *  Calls Redisplay() method for each object in the given list
1186  */
1187 //=================================================================
1188 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1189                                 const bool theUpdateViewer,
1190                                 SALOME_View* theViewFrame )
1191 {
1192   SALOME_ListIteratorOfListIO anIter( theIOList );
1193   for ( ; anIter.More(); anIter.Next() )
1194   {
1195     Redisplay( anIter.Value(), false, theViewFrame );
1196   }
1197
1198   if ( theUpdateViewer )
1199   {
1200     UpdateViewer();
1201   }
1202 }
1203
1204 //=================================================================
1205 /*!
1206  *  GEOM_Displayer::Update
1207  *  Update OCC presentaion
1208  *  [ Reimplemented from SALOME_Displayer ]
1209  */
1210 //=================================================================
1211 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1212 {
1213   SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1214   SalomeApp_Study* study = getStudy();
1215
1216   if ( !occPrs || myShape.IsNull() || !study )
1217     return;
1218
1219   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1220   {
1221     // 
1222     // specific processing for local coordinate system presentation
1223     // 
1224
1225     TopoDS_Face aFace = TopoDS::Face( myShape );
1226     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1227     if ( !aPlane.IsNull() )
1228     {
1229       gp_Ax3 aPos = aPlane->Pln().Position();
1230       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1231
1232       Handle(GEOM_AISTrihedron) aTrh;
1233
1234       if ( occPrs->IsNull() )
1235       {
1236         // new presentation is being created
1237         aTrh = new GEOM_AISTrihedron( aPlc );
1238         occPrs->AddObject( aTrh );
1239       }
1240       else
1241       {
1242         // presentation is being updated
1243         AIS_ListOfInteractive aList;
1244         occPrs->GetObjects( aList );
1245         AIS_ListIteratorOfListOfInteractive anIter( aList );
1246         for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1247           aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1248         }
1249       }
1250         
1251       if ( !aTrh.IsNull() ) {
1252         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1253         if ( HasColor() )
1254           aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1255         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1256         if ( HasWidth() )
1257           aTrh->SetWidth( GetWidth() );
1258         
1259         if ( !myIO.IsNull() )
1260         {
1261           aTrh->setIO( myIO );
1262           aTrh->SetOwner( myIO );
1263         }
1264         aTrh->SetComponent( aPlc );
1265         aTrh->SetToUpdate();
1266       }
1267       occPrs->SetToActivate( ToActivate() );
1268     }
1269   }
1270   else
1271   {
1272     // 
1273     // processing for usual geometry presentation
1274     // 
1275
1276     // if presentation is empty we try to create new one
1277     if ( occPrs->IsNull() )
1278     {
1279       // create presentation (specific for vectors)
1280       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1281                                                                  : new GEOM_AISShape ( myShape, "" );
1282
1283       if( myType == GEOM_FIELD_STEP )
1284         AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1285       // update shape properties
1286       updateShapeProperties( AISShape, true );
1287
1288       // add shape to the presentation
1289       occPrs->AddObject( AISShape );
1290
1291       // In accordance with ToActivate() value object will be activated/deactivated
1292       // when it will be displayed
1293       occPrs->SetToActivate( ToActivate() );
1294
1295       if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1296         // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1297
1298         // create additional wireframe shape
1299         Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1300         aWirePrs->SetWidth(AISShape->Width());
1301         if ( !myIO.IsNull() ) {
1302           aWirePrs->setIO( myIO );
1303           aWirePrs->SetOwner( myIO );
1304         }
1305
1306         // add shape to the presentation
1307         occPrs->AddObject( aWirePrs );
1308       }
1309     }
1310     // if presentation is found -> set again shape for it
1311     else
1312     {
1313       AIS_ListOfInteractive IOList;
1314       occPrs->GetObjects( IOList );
1315       AIS_ListIteratorOfListOfInteractive Iter( IOList );
1316       for ( ; Iter.More(); Iter.Next() )
1317       {
1318         Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1319         if ( AISShape.IsNull() )
1320           continue;
1321
1322         // re-set shape (it might be changed)
1323         if ( AISShape->Shape() != myShape )
1324           AISShape->Set( myShape );
1325
1326         // update shape properties
1327         updateShapeProperties( AISShape, false );
1328
1329         // force updating
1330         AISShape->UpdateSelection();
1331         AISShape->SetToUpdate();
1332       }
1333     }
1334
1335     updateDimensions( myIO, occPrs, GEOMUtils::GetPosition( myShape ) );
1336   }
1337 }
1338
1339 //=================================================================
1340 /*!
1341  *  GEOM_Displayer::Update
1342  *  Update VTK presentaion
1343  *  [ Reimplemented from SALOME_Displayer ]
1344  */
1345 //=================================================================
1346 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1347 {
1348   SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1349   SalomeApp_Study* study = getStudy();
1350
1351   if ( !vtkPrs || myShape.IsNull() || !study )
1352     return;
1353
1354   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1355   {
1356     // 
1357     // specific processing for local coordinate system presentation
1358     // 
1359
1360     TopoDS_Face aFace = TopoDS::Face( myShape );
1361     Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1362     if ( !aPlane.IsNull() ) {
1363       gp_Ax3 aPos = aPlane->Pln().Position();
1364       Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1365
1366       GEOM_VTKTrihedron* aTrh = 0;
1367
1368       if ( vtkPrs->IsNull() ) {
1369         // new presentation is being created
1370         aTrh = GEOM_VTKTrihedron::New();
1371         vtkPrs->AddObject( aTrh );
1372       }
1373       else {
1374         // presentation is being updated
1375         vtkActorCollection* actors = vtkPrs->GetObjects();
1376         if ( actors ) {
1377           actors->InitTraversal();
1378           vtkActor* a = actors->GetNextActor();
1379           while ( a && !aTrh ) {
1380             aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1381             a = actors->GetNextActor();
1382           }
1383         }
1384       }
1385       
1386       if ( aTrh ) {
1387         // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1388         if ( HasColor() ) {
1389           Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1390           aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1391         }
1392 #ifdef VTK_TRIHEDRON_WIDTH
1393         // 
1394         // VSR: currently isn't supported
1395         //
1396         // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function 
1397         if ( HasWidth() )
1398           aTrh->SetWidth( GetWidth() );
1399 #endif
1400
1401         if ( !myIO.IsNull() )
1402           aTrh->setIO( myIO );
1403
1404         aTrh->SetPlacement( aPlc );
1405       }
1406     }
1407   }
1408   else
1409   {
1410     // 
1411     // processing for usual geometry presentation
1412     // 
1413
1414     // if presentation is empty we try to create new one
1415     if ( vtkPrs->IsNull() )
1416     {
1417       // create an actor
1418       GEOM_Actor* actor = GEOM_Actor::New();
1419       // update actor properties
1420       updateActorProperties( actor, true );
1421       // add actor to the presentation
1422       vtkPrs->AddObject( actor );
1423     }
1424     else {
1425       // presentation is being updated
1426       vtkActorCollection* actors = vtkPrs->GetObjects();
1427       if ( actors ) {
1428         actors->InitTraversal();
1429         vtkActor* a = actors->GetNextActor();
1430         while ( a ) {
1431           GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1432           if ( actor ) {
1433             // update actor properties
1434             updateActorProperties( actor, false );
1435             a = actors->GetNextActor();
1436           }
1437         }
1438       }
1439     }
1440   }
1441 }
1442
1443 //=================================================================
1444 /*!
1445  *  GEOM_Displayer::BuildPrs
1446  *  Build presentation accordint to the current viewer type
1447  */
1448 //=================================================================
1449 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1450 {
1451   if ( theObj->_is_nil() )
1452     return 0;
1453
1454   myViewFrame = GetActiveView();
1455   if ( myViewFrame == 0 )
1456     return 0;
1457
1458   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1459   if ( aPrs == 0 )
1460     return 0;
1461
1462   internalReset();
1463   setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1464   myType = theObj->GetType();
1465
1466   // Update presentation
1467   UpdatePrs( aPrs );
1468
1469   return aPrs;
1470 }
1471
1472 //=================================================================
1473 /*!
1474  *  GEOM_Displayer::BuildPrs
1475  *  Build presentation accordint to the current viewer type
1476  */
1477 //=================================================================
1478 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1479 {
1480   myViewFrame = GetActiveView();
1481   if ( theShape.IsNull() || myViewFrame == 0 )
1482     return 0;
1483
1484   SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1485   if ( aPrs == 0 )
1486     return 0;
1487
1488   internalReset();
1489   setShape( theShape );
1490   myType = -1;
1491
1492   UpdatePrs( aPrs );
1493
1494   return aPrs;
1495 }
1496
1497 //=================================================================
1498 /*!
1499  *  GEOM_Displayer::buildPresentation
1500  *  Builds/finds object's presentation for the current viewer
1501  *  Calls corresponding Update() method by means of double dispatch
1502  *  [ internal ]
1503  */
1504 //=================================================================
1505 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1506                                                SALOME_View* theViewFrame )
1507 {
1508   SALOME_Prs* prs = 0;
1509   internalReset();
1510
1511   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1512
1513   if ( myViewFrame )
1514   {
1515     prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1516     if ( prs )
1517     {
1518       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1519       theIO->setEntry( entry.toLatin1().constData() );
1520       if ( !theIO.IsNull() )
1521       {
1522         // set interactive object
1523         setIO( theIO );
1524         //  Find SOBject (because shape should be published previously)
1525         SUIT_Session* session = SUIT_Session::session();
1526         SUIT_Application* app = session->activeApplication();
1527         if ( app )
1528         {
1529           SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1530           if ( study )
1531           {
1532             _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1533             if ( SO )
1534             {
1535               // get CORBA reference to data object
1536               CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1537               if ( !CORBA::is_nil( object ) )
1538               {
1539                 // downcast to GEOM base object
1540                 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1541                 if ( !GeomBaseObject->_is_nil() )
1542                 {
1543                   myType = GeomBaseObject->GetType();
1544
1545                   // downcast to GEOM object
1546                   GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1547                   if ( myType == GEOM_FIELD_STEP )
1548                   {
1549                     // get the GEOM object from the field's shape
1550                     GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1551                     if ( !GeomFieldStep->_is_nil() )
1552                     {
1553                       GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1554                       if ( !GeomField->_is_nil() )
1555                         GeomObject = GeomField->GetShape();
1556                     }
1557
1558                     // read the field step information
1559                     readFieldStepInfo( GeomFieldStep );
1560                   }
1561
1562                   if ( !GeomObject->_is_nil() )
1563                   {
1564                     // finally set shape
1565                     setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1566                   }
1567                 }
1568               }
1569             }
1570           }
1571         }
1572       }
1573       UpdatePrs( prs );  // Update presentation by using of the double dispatch
1574     }
1575   }
1576   return prs;
1577 }
1578
1579 //=================================================================
1580 /*!
1581  *  GEOM_Displayer::buildSubshapePresentation
1582  *  Builds/finds object's presentation for the current viewer
1583  *  Calls corresponding Update() method by means of double dispatch
1584  *  For not published objects (for Mantis issue 0020435)
1585  */
1586 //=================================================================
1587 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1588                                                       const QString& entry,
1589                                                       SALOME_View* theViewFrame)
1590 {
1591   SALOME_Prs* prs = 0;
1592   internalReset();
1593
1594   myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1595
1596   if (myViewFrame)
1597   {
1598     prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1599     if (prs)
1600     {
1601       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1602       theIO->setEntry(entry.toLatin1().constData());
1603       if (!theIO.IsNull())
1604       {
1605         // set interactive object
1606         setIO(theIO);
1607         // finally set shape
1608         setShape(aShape);
1609         myType = GEOM_SUBSHAPE;
1610       }
1611       UpdatePrs(prs);  // Update presentation by using of the double dispatch
1612     }
1613   }
1614   return prs;
1615 }
1616
1617 //=================================================================
1618 /*!
1619  *  GEOM_Displayer::internalReset
1620  *  Resets internal data
1621  *  [internal]
1622  */
1623 //=================================================================
1624 void GEOM_Displayer::internalReset()
1625 {
1626   myIO.Nullify();
1627   myShape.Nullify();
1628
1629   myFieldDataType = GEOM::FDT_Double;
1630   myFieldDimension = 0;
1631   myFieldStepData.clear();
1632   myFieldStepName.Clear();
1633   myFieldStepRangeMin = 0;
1634   myFieldStepRangeMax = 0;
1635 }
1636
1637 //=================================================================
1638 /*!
1639  *  GEOM_Displayer::LocalSelection
1640  *  Activate selection of CAD shapes with activisation of selection
1641  *  of their sub-shapes (with opened local context for OCC viewer)
1642  */
1643 //=================================================================
1644 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1645 {
1646   SUIT_Session* session = SUIT_Session::session();
1647   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1648   if ( !app )
1649     return;
1650
1651   LightApp_SelectionMgr* sm = app->selectionMgr();
1652
1653   // remove all filters from selection
1654   sm->clearFilters();
1655
1656   SALOME_View* vf = GetActiveView();
1657   if ( vf ) {
1658     if (!theIO.IsNull() && !vf->isVisible(theIO))
1659       Display(theIO);
1660     SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1661     vf->LocalSelection( prs, theMode );
1662     delete prs;  // delete presentation because displayer is its owner
1663   }
1664 }
1665
1666 //=================================================================
1667 /*!
1668  *  GEOM_Displayer::globalSelection
1669  *  Activate selection of CAD shapes without activisation of selection
1670  *  of their sub-shapes (without opened local context for OCC viewer)
1671  */
1672 //=================================================================
1673 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1674 {
1675   TColStd_MapOfInteger aModes;
1676   aModes.Add( theMode );
1677   GlobalSelection( aModes, update );
1678 }
1679
1680 //=================================================================
1681 /*!
1682  *  GEOM_Displayer::globalSelection
1683  *  Activate selection of CAD shapes without activisation of selection
1684  *  of their sub-shapes (without opened local context for OCC viewer)
1685  */
1686 //=================================================================
1687 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1688                                       const bool update, const QList<int>* theSubShapes )
1689 {
1690   SUIT_Session* session = SUIT_Session::session();
1691   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1692   if ( !app )
1693     return;
1694
1695   SALOME_View* vf = GetActiveView();
1696   if ( vf == 0 )
1697     return;
1698
1699   // Close local context
1700   vf->GlobalSelection( update );
1701
1702   // Set selection filters in accordance with current mode
1703   LightApp_SelectionMgr* sm = app->selectionMgr();
1704   if ( !sm )
1705     return;
1706
1707   // Remove from selection temporary objects if necessary
1708   if ( !theModes.Contains( GEOM_PREVIEW ) )
1709     clearTemporary( sm );
1710
1711   //@ aSel->ClearIndex();
1712
1713   sm->clearFilters();
1714
1715   // Remove filters from AIS_InteractiveContext
1716   Handle(AIS_InteractiveContext) ic;
1717   SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1718   if ( viewer )
1719     {
1720       ic = viewer->getAISContext();
1721       if ( !ic.IsNull() )
1722         ic->RemoveFilters();
1723     }
1724
1725   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1726     return;
1727
1728   SUIT_SelectionFilter* aFilter;
1729   if ( theModes.Extent() == 1 )
1730     {
1731       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1732
1733       if ( aMode == GEOM_COMPOUNDFILTER )
1734         aFilter = getComplexFilter( theSubShapes );
1735       else
1736         aFilter = getFilter( aMode );
1737     }
1738   else if ( theModes.Extent() > 1 )
1739     {
1740       TColStd_MapOfInteger aTopAbsModes;
1741       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1742       QList<SUIT_SelectionFilter*> aListOfFilters;
1743       for ( ; anIter.More(); anIter.Next() )
1744         {
1745           SUIT_SelectionFilter* aFilter;
1746           int aMode = anIter.Key();
1747           if ( aMode == GEOM_COMPOUNDFILTER )
1748             aFilter = getComplexFilter( theSubShapes );
1749           else
1750             aFilter = getFilter( aMode );
1751
1752           if ( aFilter )
1753             aListOfFilters.append( aFilter );
1754         }
1755
1756       aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1757     }
1758   else
1759     return;
1760
1761   if ( aFilter )
1762     {
1763       sm->installFilter( aFilter );
1764       if ( !ic.IsNull() )
1765         {
1766           Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1767           ic->AddFilter( anOCCFilter );
1768         }
1769     }
1770 }
1771
1772 //=================================================================
1773 /*!
1774  *  GEOM_Displayer::LocalSelection
1775  *  Activate selection of CAD shapes with activisation of selection
1776  *  of their sub-shapes (with opened local context for OCC viewer)
1777  */
1778 //=================================================================
1779 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1780 {
1781   SALOME_ListIteratorOfListIO Iter( theIOList );
1782   for ( ; Iter.More(); Iter.Next() )
1783     LocalSelection( Iter.Value(), theMode );
1784 }
1785
1786 //=================================================================
1787 /*!
1788  *  GEOM_Displayer::BeforeDisplay
1789  *  Called before displaying of pars. Close local context
1790  *  [ Reimplemented from SALOME_Displayer ]
1791  */
1792 //=================================================================
1793 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1794 {
1795   SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1796   if ( vf )
1797   {
1798     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1799     if ( !ic.IsNull() )
1800     {
1801       if ( ic->HasOpenedContext() )
1802       ic->CloseAllContexts();
1803     }
1804   }
1805 }
1806
1807 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1808 {
1809   UpdateColorScale(false,false);
1810 }
1811
1812 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
1813 {
1814   LightApp_Displayer::AfterErase( v, p );
1815   UpdateColorScale(false,false);
1816 }
1817
1818 //=================================================================
1819 /*!
1820  *  GEOM_Displayer::SetColor
1821  *  Set color for shape displaying. If it is equal -1 then default color is used.
1822  *  Available values are from Quantity_NameOfColor enumeration
1823  */
1824 //=================================================================
1825 void GEOM_Displayer::SetColor( const int color )
1826 {
1827   if ( color == -1 )
1828     UnsetColor();
1829   else
1830   {
1831     myColor = color;
1832     myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
1833   }
1834 }
1835
1836 int GEOM_Displayer::GetColor() const
1837 {
1838   return myColor;
1839 }
1840
1841 bool GEOM_Displayer::HasColor() const
1842 {
1843   return myColor != -1;
1844 }
1845
1846 void GEOM_Displayer::UnsetColor()
1847 {
1848   myColor = -1;
1849
1850   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1851   QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
1852   myShadingColor = SalomeApp_Tools::color( col );
1853 }
1854
1855 //=================================================================
1856 /*!
1857  *  GEOM_Displayer::SetTexture
1858  *  Set color for shape displaying. If it is equal -1 then default color is used.
1859  *  Available values are from Quantity_NameOfColor enumeration
1860  */
1861 //=================================================================
1862 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
1863 {
1864   if(texureFileName!="")
1865   {
1866     myTexture = texureFileName;
1867   }
1868 }
1869
1870 bool GEOM_Displayer::HasTexture() const
1871 {
1872   return myTexture != "";
1873 }
1874
1875 std::string GEOM_Displayer::GetTexture() const
1876 {
1877   return myTexture;
1878 }
1879
1880 //=================================================================
1881 /*!
1882  *  GEOM_Displayer::SetWidth
1883  *  Set width of shape displaying. If it is equal -1 then default width is used.
1884  */
1885 //=================================================================
1886 void GEOM_Displayer::SetWidth( const double width )
1887 {
1888   myWidth = width;
1889 }
1890
1891 double GEOM_Displayer::GetWidth() const
1892 {
1893   return myWidth;
1894 }
1895
1896 bool GEOM_Displayer::HasWidth() const
1897 {
1898   return myWidth != -1;
1899 }
1900
1901 void GEOM_Displayer::UnsetWidth()
1902 {
1903   myWidth = -1;
1904 }
1905
1906
1907 int GEOM_Displayer::GetIsosWidth() const
1908 {
1909   return myIsosWidth;
1910 }
1911
1912 void GEOM_Displayer::SetIsosWidth(const int width)
1913 {
1914   myIsosWidth = width;
1915 }
1916
1917 bool GEOM_Displayer::HasIsosWidth() const
1918 {
1919   return myIsosWidth != -1;
1920 }
1921
1922
1923 //=================================================================
1924 /*!
1925  *  GEOM_Displayer::SetToActivate
1926  *  This method is used for activisation/deactivisation of objects to be displayed
1927  */
1928 //=================================================================
1929 void GEOM_Displayer::SetToActivate( const bool toActivate )
1930 {
1931   myToActivate = toActivate;
1932 }
1933 bool GEOM_Displayer::ToActivate() const
1934 {
1935   return myToActivate;
1936 }
1937
1938 //=================================================================
1939 /*!
1940  *  GEOM_Displayer::clearTemporary
1941  *  Removes from selection temporary objects
1942  */
1943 //=================================================================
1944 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
1945 {
1946   SALOME_ListIO selected, toSelect;
1947   theSelMgr->selectedObjects( selected );
1948
1949   for (  SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
1950     Handle(SALOME_InteractiveObject) io = it.Value();
1951     if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
1952       toSelect.Append( it.Value() );
1953   }
1954
1955   theSelMgr->setSelectedObjects( toSelect, true );
1956 }
1957
1958 void GEOM_Displayer::SetName( const char* theName )
1959 {
1960   myName = theName;
1961 }
1962
1963 void GEOM_Displayer::UnsetName()
1964 {
1965   myName = "";
1966 }
1967
1968 SalomeApp_Study* GEOM_Displayer::getStudy() const
1969 {
1970   return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
1971 }
1972
1973 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
1974 {
1975   myIO = theIO;
1976 }
1977
1978 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
1979 {
1980   myShape = theShape;
1981 }
1982
1983 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
1984                                        const int theFieldDimension,
1985                                        const QList<QVariant>& theFieldStepData,
1986                                        const TCollection_AsciiString& theFieldStepName,
1987                                        const double theFieldStepRangeMin,
1988                                        const double theFieldStepRangeMax )
1989 {
1990   myFieldDataType = theFieldDataType;
1991   myFieldDimension = theFieldDimension;
1992   myFieldStepData = theFieldStepData;
1993   myFieldStepName = theFieldStepName;
1994   myFieldStepRangeMin = theFieldStepRangeMin;
1995   myFieldStepRangeMax = theFieldStepRangeMax;
1996 }
1997
1998 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
1999 {
2000   _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2001   GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2002   GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2003   GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2004   return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2005          (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2006 }
2007
2008 int GEOM_Displayer::SetDisplayMode( const int theMode )
2009 {
2010   int aPrevMode = myDisplayMode;
2011   if ( theMode != -1 ) {
2012     myDisplayMode = theMode;
2013     myHasDisplayMode = true;
2014   }
2015   else {
2016     UnsetDisplayMode();
2017   }
2018   return aPrevMode;
2019 }
2020
2021 int GEOM_Displayer::GetDisplayMode() const
2022 {
2023   return myDisplayMode;
2024 }
2025
2026 int GEOM_Displayer::UnsetDisplayMode()
2027 {
2028   int aPrevMode = myDisplayMode;
2029   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2030   myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2031   myHasDisplayMode = false;
2032   return aPrevMode;
2033 }
2034
2035 bool GEOM_Displayer::HasDisplayMode() const
2036 {
2037   return myHasDisplayMode;
2038 }
2039
2040 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2041 {
2042   static QList<QColor> colors;
2043
2044   if ( colors.isEmpty() ) {
2045
2046     for (int s = 0; s < 2 ; s++)
2047     {
2048       for (int v = 100; v >= 40; v = v - 20)
2049       {
2050         for (int h = 0; h < 359 ; h = h + 60)
2051         {
2052           colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2053         }
2054       }
2055     }
2056   }
2057
2058   static int currentColor = 0;
2059
2060   SALOMEDS::Color color;
2061   color.R = (double)colors[currentColor].red()   / 255.0;
2062   color.G = (double)colors[currentColor].green() / 255.0;
2063   color.B = (double)colors[currentColor].blue()  / 255.0;
2064
2065   currentColor = (currentColor+1) % colors.count();
2066
2067   return color;
2068 }
2069
2070 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2071 {
2072   int aHue = -1;
2073   int aTolerance = 64;
2074   int anIterations = 0;
2075   int aPeriod = 5;
2076
2077   while( 1 )
2078   {
2079     anIterations++;
2080     if( anIterations % aPeriod == 0 )
2081     {
2082       aTolerance /= 2;
2083       if( aTolerance < 1 )
2084         break;
2085     }
2086     //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2087
2088     aHue = (int)( 360.0 * rand() / RAND_MAX );
2089     //std::cout << "Hue = " << aHue << std::endl;
2090
2091     //std::cout << "Auto colors : ";
2092     bool ok = true;
2093     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2094     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2095     for( ; it != itEnd; ++it )
2096     {
2097       SALOMEDS::Color anAutoColor = *it;
2098       QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2099
2100       int h, s, v;
2101       aQColor.getHsv( &h, &s, &v );
2102       //std::cout << h << " ";
2103       if( abs( h - aHue ) < aTolerance )
2104       {
2105         ok = false;
2106         //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2107         break;
2108       }
2109     }
2110     //std::cout << std::endl;
2111
2112     if( ok )
2113       break;
2114   }
2115
2116   //std::cout << "Hue of the returned color = " << aHue << std::endl;
2117   QColor aColor;
2118   aColor.setHsv( aHue, 255, 255 );
2119
2120   SALOMEDS::Color aSColor;
2121   aSColor.R = (double)aColor.red() / 255.0;
2122   aSColor.G = (double)aColor.green() / 255.0;
2123   aSColor.B = (double)aColor.blue() / 255.0;
2124
2125   return aSColor;
2126 }
2127
2128 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2129                                              const QString& entry,
2130                                              SALOME_View* view )
2131 {
2132   // get default properties for the explicitly specified default view type
2133   PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2134
2135   if ( study && view ) {
2136     SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2137     SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2138     int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2139   
2140     if ( viewModel && viewId != -1 ) {
2141       // get properties from the study
2142       PropMap storedMap = study->getObjectPropMap( viewId, entry );
2143       // overwrite default properties from stored ones (that are specified)
2144       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2145         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2146           propMap.insert( GEOM::propertyName( (GEOM::Property)prop ), 
2147                           storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2148       }
2149       // ... specific processing for color
2150       // ... current implementation is to use same stored color for all aspects
2151       // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2152       if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2153         propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2154         propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2155         propMap.insert( GEOM::propertyName( GEOM::LineColor ),      storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2156         propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2157         propMap.insert( GEOM::propertyName( GEOM::PointColor ),     storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2158       }
2159
2160       if ( !entry.isEmpty() ) {
2161         // get CORBA reference to geom object
2162         _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2163         if ( SO ) {
2164           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2165           if ( !CORBA::is_nil( object ) ) {
2166             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2167             if ( !CORBA::is_nil( geomObject ) ) { // to check
2168               // check that geom object has color properly set
2169               bool hasColor = false;
2170               SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2171               // set color from geometry object (only once, if it is not yet set in GUI)
2172               // current implementation is to use same color for all aspects
2173               // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2174               if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2175                 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2176                 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),   objColor );
2177                 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2178                 propMap.insert( GEOM::propertyName( GEOM::LineColor ),      objColor );
2179                 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),   objColor );
2180                 propMap.insert( GEOM::propertyName( GEOM::PointColor ),     objColor );
2181               }
2182               // check that object has point marker properly set
2183               GEOM::marker_type mType = geomObject->GetMarkerType();
2184               GEOM::marker_size mSize = geomObject->GetMarkerSize();
2185               int mTextureId = geomObject->GetMarkerTexture();
2186               bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || 
2187                                ( mType == GEOM::MT_USER && mTextureId > 0 );
2188               // set point marker from geometry object (only once, if it is not yet set in GUI)
2189               if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2190                 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2191                   // standard type
2192                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2193                                   QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2194                 }
2195                 else if ( mType == GEOM::MT_USER ) {
2196                   // custom texture
2197                   propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2198                 }
2199               }
2200             }
2201           }
2202         }
2203       }
2204     }
2205   }
2206   return propMap;
2207 }
2208
2209 PropMap GEOM_Displayer::getDefaultPropertyMap()
2210 {
2211   PropMap propMap;
2212
2213   // get resource manager
2214   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2215
2216   // fill in the properties map with default values
2217
2218   // - visibility (false by default)
2219   propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2220
2221   // - nb isos (take default value from preferences)
2222   propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2223                   QString( "%1%2%3" ).
2224                   arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2225                   arg( GEOM::subSectionSeparator() ).
2226                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2227
2228   // - transparency (opacity = 1-transparency)
2229   propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2230
2231   // - display mode (take default value from preferences)
2232   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2233                   resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2234
2235   // - show edges direction flag (false by default)
2236   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2237
2238   // - shading color (take default value from preferences)
2239   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2240                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2241
2242   // - wireframe color (take default value from preferences)
2243   propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2244                   colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2245
2246   // - standalone edges color (take default value from preferences)
2247   propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2248                   colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2249
2250   // - free boundaries color (take default value from preferences)
2251   propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2252                   colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2253
2254   // - points color (take default value from preferences)
2255   propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2256                   colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2257
2258   // - isos color (take default value from preferences)
2259   propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2260                   colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2261
2262   // - outlines color (take default value from preferences)
2263   propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2264                   colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2265
2266   // - deflection coefficient (take default value from preferences)
2267   propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2268                   resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2269
2270   // - material (take default value from preferences)
2271   Material_Model material;
2272   material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2273   propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2274
2275   // - edge width (take default value from preferences)
2276   propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2277                   resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2278
2279   // - isos width (take default value from preferences)
2280   propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2281                   resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2282
2283   // - point marker (take default value from preferences)
2284   propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2285                   QString( "%1%2%3" ).
2286                   arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2287                   arg( GEOM::subSectionSeparator() ).
2288                   arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2289
2290   // - top-level flag (false by default)
2291   propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2292
2293   return propMap;
2294 }
2295
2296 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2297   SALOMEDS::Color aSColor;
2298   hasColor = false;
2299
2300   SUIT_Session* session = SUIT_Session::session();
2301   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2302
2303   if ( app && !theGeomObject->_is_nil()) {
2304     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2305
2306     if ( study ) {
2307       _PTR(Study) aStudy = study->studyDS();
2308       aSColor = theGeomObject->GetColor();
2309       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2310       if ( !hasColor ) {
2311 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2312         bool general_autocolor = true;
2313 #else                    // auto-color for groups only
2314         bool general_autocolor = false;
2315 #endif                   // GENERAL_AUTOCOLOR
2316         if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2317           GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2318           if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2319 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
2320             aSColor = getPredefinedUniqueColor();
2321             hasColor = true;
2322 #else                    // old algorithm  for auto-colors
2323             QList<SALOMEDS::Color> aReservedColors;
2324             CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2325             _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2326             if ( aMainSObject ) {
2327               _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2328               for ( ; it->More(); it->Next() ) {
2329                 _PTR(SObject) aChildSObject( it->Value() );
2330                 GEOM::GEOM_Object_var aChildObject =
2331                   GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2332                 if ( CORBA::is_nil( aChildObject ) )
2333                   continue;
2334
2335                 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2336                 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2337                   aReservedColors.append( aReservedColor );
2338               }
2339             }
2340             aSColor = getUniqueColor( aReservedColors );
2341             hasColor = true;
2342 #endif                   // SIMPLE_AUTOCOLOR
2343           }
2344         }
2345       }
2346     }
2347   }
2348   return aSColor;
2349 }
2350
2351
2352 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2353                                        const bool eraseOnlyChildren) {
2354   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2355   if ( !app )
2356     return;
2357
2358   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2359   if ( !appStudy )
2360     return;
2361
2362   LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2363
2364   if( !parent)
2365     return;
2366
2367   // Erase from all views
2368   QList<SALOME_View*> views;
2369   SALOME_View* view;
2370   ViewManagerList vmans = app->viewManagers();
2371   SUIT_ViewManager* vman;
2372   foreach ( vman, vmans ) {
2373     SUIT_ViewModel* vmod = vman->getViewModel();
2374     view = dynamic_cast<SALOME_View*> ( vmod );
2375     if ( view )
2376       views.append( view );
2377   }
2378
2379   if( views.count() == 0 )
2380     return;
2381
2382   //Erase childrens w/o update views
2383   DataObjectList listObj = parent->children( true );
2384   SUIT_DataObject* obj;
2385   foreach( obj, listObj ) {
2386     LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2387     if(l_obj)
2388       foreach ( view, views ) {
2389       Handle(SALOME_InteractiveObject) anIO =
2390         new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2391       Erase(anIO, false, false, view);
2392     }
2393   }
2394
2395   //Erase parent with view update or repaint views
2396   foreach ( view, views ) {
2397     if(!eraseOnlyChildren)
2398       Erase(theIO, false, true, view);
2399     else
2400       view->Repaint();
2401   }
2402 }
2403
2404 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2405 {
2406   if( theGeomFieldStep->_is_nil() )
2407     return;
2408
2409   GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2410   if( aGeomField->_is_nil() )
2411     return;
2412
2413   GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2414   if( aGeomFieldShape->_is_nil() )
2415     return;
2416
2417   TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2418   TCollection_AsciiString aFieldName( aGeomField->GetName() );
2419   TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2420
2421   aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2422
2423   GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2424
2425   int aFieldDimension = aGeomField->GetDimension();
2426
2427   GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2428   int aFieldNbComponents = aFieldComponents->length();
2429
2430   QList<QVariant> aFieldStepData;
2431   if( aFieldDataType == GEOM::FDT_Bool )
2432   {
2433     GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2434     if ( !aGeomBoolFieldStep->_is_nil() )
2435     {
2436       GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2437       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2438         aFieldStepData << (bool)aValues[i];
2439     }
2440   }
2441   else if( aFieldDataType == GEOM::FDT_Int )
2442   {
2443     GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2444     if ( !aGeomIntFieldStep->_is_nil() )
2445     {
2446       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2447       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2448         aFieldStepData << (qlonglong)aValues[i];
2449     }
2450   }
2451   else if( aFieldDataType == GEOM::FDT_Double )
2452   {
2453     GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2454     if ( !aGeomDoubleFieldStep->_is_nil() )
2455     {
2456       GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2457       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2458         aFieldStepData << (double)aValues[i];
2459     }
2460   }
2461   else if( aFieldDataType == GEOM::FDT_String )
2462   {
2463     GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2464     if ( !aGeomStringFieldStep->_is_nil() )
2465     {
2466       GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2467       for( size_t i = 0, n = aValues->length(); i < n; i++ )
2468         aFieldStepData << QString( aValues[i] );
2469     }
2470   }
2471
2472   double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2473   aFieldStepData = groupFieldData( aFieldStepData,
2474                                    aFieldNbComponents,
2475                                    aFieldDataType == GEOM::FDT_String,
2476                                    aFieldStepRangeMin,
2477                                    aFieldStepRangeMax );
2478
2479   setFieldStepInfo( aFieldDataType,
2480                     aFieldDimension,
2481                     aFieldStepData,
2482                     aFieldStepName,
2483                     aFieldStepRangeMin,
2484                     aFieldStepRangeMax );
2485 }
2486
2487 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2488                                                 const int theFieldNbComponents,
2489                                                 const bool theIsString,
2490                                                 double& theFieldStepRangeMin,
2491                                                 double& theFieldStepRangeMax )
2492 {
2493   QList<QVariant> aResultList;
2494   theFieldStepRangeMin = 0;
2495   theFieldStepRangeMax = 0;
2496
2497   if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2498     return aResultList;
2499
2500   int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2501
2502   QList<QVariant> aGroupedList;
2503
2504   bool anIsBoolean = false;
2505   for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2506   {
2507     double aNorm = 0;
2508     QStringList aStringList;
2509
2510     int aBaseIndex = aSubShape * theFieldNbComponents;
2511     for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2512     {
2513       int anIndex = aComponent + aBaseIndex;
2514
2515       const QVariant& aVariant = theFieldStepData[ anIndex ];
2516       if( theIsString )
2517       {
2518         if( aVariant.type() == QVariant::String )
2519           aStringList << aVariant.toString();
2520       }
2521       else
2522       {
2523         double aValue = 0;
2524         if( aVariant.type() == QVariant::Bool )
2525         {
2526           aValue = aVariant.toBool() ? 1.0 : 0.0;
2527           aNorm += aValue;
2528           anIsBoolean = true;
2529         }
2530         else
2531         {
2532           if( aVariant.type() == QVariant::Int )
2533             aValue = double( aVariant.toInt() );
2534           else if( aVariant.type() == QVariant::Double )
2535             aValue = aVariant.toDouble();
2536           aNorm += aValue * aValue;
2537         }
2538       }
2539     }
2540
2541     if( theIsString )
2542       aGroupedList << aStringList.join( "\n" );
2543     else
2544     {
2545       if( anIsBoolean )
2546         aNorm /= theFieldNbComponents;
2547       else
2548         aNorm = pow( aNorm, 0.5 );
2549
2550       if( aGroupedList.isEmpty() )
2551         theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2552       else
2553       {
2554         theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2555         theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2556       }
2557
2558       aGroupedList << aNorm;
2559     }
2560   }
2561
2562   if( anIsBoolean )
2563   {
2564     theFieldStepRangeMin = 0.0;
2565     theFieldStepRangeMax = 1.0;
2566   }
2567
2568   SUIT_Session* session = SUIT_Session::session();
2569   SUIT_ResourceMgr* resMgr = session->resourceMgr();
2570   Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2571
2572   QListIterator<QVariant> anIter( aGroupedList );
2573   while( anIter.hasNext() )
2574   {
2575     const QVariant& aVariant = anIter.next();
2576     if( theIsString )
2577       aResultList << aVariant;
2578     else
2579     {
2580       QColor aQColor;
2581       Quantity_Color aColor;
2582       if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2583         aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2584       aResultList << aQColor;
2585     }
2586   }
2587   return aResultList;
2588 }
2589
2590 // Note: the method is copied from Aspect_ColorScale class
2591 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2592                                                const Standard_Integer aMin,
2593                                                const Standard_Integer aMax )
2594 {
2595   Standard_Integer minLimit( 0 ), maxLimit( 230 );
2596
2597   Standard_Integer aHue = maxLimit;
2598   if ( aMin != aMax )
2599     aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2600
2601   aHue = Min( Max( minLimit, aHue ), maxLimit );
2602
2603   return aHue;
2604 }
2605
2606 // Note: the method is copied from Aspect_ColorScale class
2607 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, 
2608                                             const Standard_Real aMin,
2609                                             const Standard_Real aMax,
2610                                             const Standard_Integer ColorsCount,
2611                                             Quantity_Color& aColor )
2612 {
2613   if( aValue<aMin || aValue>aMax || aMax<aMin )
2614     return Standard_False;
2615
2616   else
2617   {
2618     Standard_Real IntervNumber = 0;
2619     if( aValue<aMin )
2620       IntervNumber = 0;
2621     else if( aValue>aMax )
2622       IntervNumber = ColorsCount-1;
2623     else if( Abs( aMax-aMin ) > Precision::Approximation() )
2624       IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2625
2626     Standard_Integer Interv = Standard_Integer( IntervNumber );
2627
2628     aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2629
2630     return Standard_True;
2631   } 
2632 }
2633
2634 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
2635 {
2636   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2637   if( !aStudy )
2638     return;
2639
2640   SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2641   if( !aViewModel )
2642     return;
2643
2644   Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2645   if( aViewer.IsNull() )
2646     return;
2647
2648   aViewer->InitActiveViews();
2649   if( !aViewer->MoreActiveViews() )
2650     return;
2651
2652   Handle(V3d_View) aView = aViewer->ActiveView();
2653   if( aView.IsNull() )
2654     return;
2655
2656   Standard_Boolean anIsDisplayColorScale = Standard_False;
2657   TCollection_AsciiString aColorScaleTitle;
2658   Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2659   Standard_Boolean anIsBoolean = Standard_False;
2660
2661   SALOME_ListIO aSelectedObjects;
2662   myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2663   if( aSelectedObjects.Extent() == 1 )
2664   {
2665     Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2666     if( !anIO.IsNull() )
2667     {
2668       SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2669       if( aPrs )
2670       {
2671         AIS_ListOfInteractive aList;
2672         aPrs->GetObjects( aList );
2673         AIS_ListIteratorOfListOfInteractive anIter( aList );
2674         for( ; anIter.More(); anIter.Next() )
2675         {
2676           Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2677           if( !aShape.IsNull() )
2678           {
2679             GEOM::field_data_type aFieldDataType;
2680             int aFieldDimension;
2681             QList<QVariant> aFieldStepData;
2682             TCollection_AsciiString aFieldStepName;
2683             double aFieldStepRangeMin, aFieldStepRangeMax;
2684             aShape->getFieldStepInfo( aFieldDataType,
2685                                       aFieldDimension,
2686                                       aFieldStepData,
2687                                       aFieldStepName,
2688                                       aFieldStepRangeMin,
2689                                       aFieldStepRangeMax );
2690             if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2691             {
2692               anIsDisplayColorScale = Standard_True;
2693               aColorScaleTitle = aFieldStepName;
2694               aColorScaleMin = aFieldStepRangeMin;
2695               aColorScaleMax = aFieldStepRangeMax;
2696               anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2697             }
2698           }
2699         }
2700       }
2701     }
2702   }
2703
2704   if( anIsDisplayColorScale )
2705   {
2706     Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2707     if( !aColorScale.IsNull() )
2708     {
2709       SUIT_Session* session = SUIT_Session::session();
2710       SUIT_ResourceMgr* resMgr = session->resourceMgr();
2711
2712       Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2713       Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2714       Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2715       Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2716       Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2717       Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2718  
2719       aColorScale->SetXPosition( anXPos );
2720       aColorScale->SetYPosition( anYPos );
2721       aColorScale->SetWidth( aWidth );
2722       aColorScale->SetHeight( aHeight );
2723
2724       aColorScale->SetTextHeight( aTextHeight );
2725       aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2726
2727       aColorScale->SetTitle( aColorScaleTitle );
2728       aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2729     }
2730     if( !aView->ColorScaleIsDisplayed() )
2731       aView->ColorScaleDisplay();
2732   }
2733   else
2734   {
2735     if( aView->ColorScaleIsDisplayed() )
2736       aView->ColorScaleErase();
2737   }
2738
2739   if( theIsRedisplayFieldSteps )
2740   {
2741     _PTR(Study) aStudyDS = aStudy->studyDS();
2742     QList<SUIT_ViewManager*> vmList;
2743     myApp->viewManagers( vmList );
2744     for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2745     {
2746       if( SUIT_ViewManager* aViewManager = *vmIt )
2747       {
2748         const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2749         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2750         {
2751           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2752           if( aSObj )
2753           {
2754             CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2755             if( !CORBA::is_nil( anObject ) )
2756             {
2757               GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2758               if( !aFieldStep->_is_nil() )
2759               {
2760                 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2761                 Handle(SALOME_InteractiveObject) aStepIO =
2762                   new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2763                 Redisplay( aStepIO, false, false );
2764               }
2765             }
2766           }
2767         }
2768       }
2769     }
2770   }
2771   if(updateViewer)
2772     UpdateViewer();
2773 }