1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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)
27 #include "GEOM_Displayer.h"
28 #include "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
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>
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>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
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>
59 #include <Basics_OCCTVersion.hxx>
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>
68 #include <SALOME_ListIO.hxx>
69 #include <SALOME_Prs.h>
72 #include <SOCC_ViewModel.h>
75 #include <SVTK_ViewModel.h>
77 #include <OCCViewer_ViewWindow.h>
78 #include <OCCViewer_ViewPort3d.h>
79 #include <OCCViewer_Utilities.h>
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 #include <NCollection_DataMap.hxx>
110 #include <NCollection_Map.hxx>
112 #include <Prs3d_ShadingAspect.hxx>
114 #include <BRepMesh_IncrementalMesh.hxx>
117 #include <vtkActorCollection.h>
118 #include <vtkProperty.h>
121 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
123 #include <GEOMImpl_Types.hxx>
125 #include <TColStd_HArray1OfByte.hxx>
127 // If the next macro is defined, autocolor feature works for all sub-shapes;
128 // if it is undefined, autocolor feature works for groups only
129 #define GENERAL_AUTOCOLOR
130 // Below macro, when uncommented, switches on simplified (more performant) algorithm
131 // of auto-color picking up
132 #define SIMPLE_AUTOCOLOR
134 // Hard-coded value of shape deflection coefficient for VTK viewer
135 const double VTK_MIN_DEFLECTION = 0.001;
137 // Pixmap caching support
140 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
141 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
142 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
144 static inline PixmapUsageMap& getPixmapUsageMap()
146 static PixmapUsageMap aMap;
150 static inline PixmapCacheMap& getPixmapCacheMap()
152 static PixmapCacheMap aMap;
156 //===========================================================================
157 // Function : getDefaultTexture
158 // Purpose : Get default texture
159 //===========================================================================
160 static inline Handle(Image_PixMap) getDefaultTexture()
162 static Handle(Image_PixMap) aPixmap;
163 if ( aPixmap.IsNull() ) {
164 QPixmap px(":images/default_texture.png");
166 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
171 //===========================================================================
172 // Function : cacheTextureFor
173 // Purpose : Load and cache image for the specified presentation.
174 //===========================================================================
175 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
176 const Handle(GEOM_AISShape)& theShape )
178 if ( thePath.isEmpty() )
181 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
182 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
184 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
185 if ( !aPixmap.IsNull() ) {
186 // point that the texture is used by the presentation
187 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
188 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
190 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
195 // convert texture to compatible image format
196 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
197 if ( anImage.isNull() )
200 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
202 aPixmapCacheMap.insert( thePath, aPixmap );
204 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
205 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
207 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
212 //===========================================================================
213 // Function : releaseTextures
214 // Purpose : Releases cached textures found for the specified presentation.
215 //===========================================================================
216 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
218 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
220 AIS_ListOfInteractive aListOfIO;
222 anOccPrs->GetObjects( aListOfIO );
224 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
226 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
227 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
229 for ( ; aIterateIO.More(); aIterateIO.Next() )
231 Handle(GEOM_AISShape) aAISShape =
232 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
234 if ( aAISShape.IsNull() )
237 #ifdef USE_TEXTURED_SHAPE
238 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
239 if ( aPixmap.IsNull() )
242 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
245 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
247 aUsersShapes.Remove( aAISShape );
249 if ( aUsersShapes.IsEmpty() ) {
250 aPixmapUsersMap.UnBind( aPixmap );
251 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
257 uint randomize( uint size )
259 static bool initialized = false;
260 if ( !initialized ) {
261 qsrand( QDateTime::currentDateTime().toTime_t() );
265 v = uint( (double)( v ) / RAND_MAX * size );
266 v = qMax( uint(0), qMin ( v, size-1 ) );
271 //================================================================
272 // Function : getActiveStudy
273 // Purpose : Get active study, returns 0 if no open study frame
274 //================================================================
275 static inline SalomeApp_Study* getActiveStudy()
277 SUIT_Session* session = SUIT_Session::session();
278 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
280 return ( SalomeApp_Study* )app->activeStudy();
284 static inline int getViewManagerId( SALOME_View* theViewFrame) {
285 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
286 SUIT_ViewManager* aViewMgr = 0;
288 aViewMgr = aModel->getViewManager();
289 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
292 //================================================================
293 // Function : getTopAbsMode
294 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
295 // one from GEOMImpl_Types.h
296 //================================================================
297 static inline int getTopAbsMode( const int implType )
301 case GEOM_COMPOUND : return TopAbs_COMPOUND;
302 case GEOM_SOLID : return TopAbs_SOLID;
303 case GEOM_SHELL : return TopAbs_SHELL;
304 case GEOM_FACE : return TopAbs_FACE;
305 case GEOM_WIRE : return TopAbs_WIRE;
306 case GEOM_EDGE : return TopAbs_EDGE;
307 case GEOM_POINT : return TopAbs_VERTEX;
312 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
314 if ( shape.IsNull() )
317 int ret = shape.ShapeType();
319 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
320 TopoDS_Iterator it(shape, Standard_True, Standard_False);
321 for (; it.More(); it.Next()) {
322 TopoDS_Shape sub_shape = it.Value();
323 if ( sub_shape.IsNull() ) continue;
324 int stype = getMinMaxShapeType( sub_shape, ismin );
325 if ( stype == TopAbs_SHAPE ) continue;
326 if ( ismin && stype > ret )
328 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
336 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
338 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
341 //================================================================
342 // Function : getFilter
343 // Purpose : Get filter corresponding to the type of object
344 // from GEOMImpl_Types.h
345 //================================================================
346 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
348 SUIT_SelectionFilter* aFilter;
350 int aTopAbsMode = getTopAbsMode( theMode );
351 if ( aTopAbsMode != -1 )
352 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
356 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
357 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
359 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
360 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
361 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
362 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
363 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
364 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
366 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
368 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
369 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
371 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
377 //================================================================
378 // Function : getComplexFilter
379 // Purpose : Get compound filter corresponding to the type of
380 // object from GEOMImpl_Types.h
381 //================================================================
382 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
384 GEOM_CompoundFilter* aFilter;
386 if(aSubShapes != NULL ) {
387 aFilter = new GEOM_CompoundFilter(getStudy());
388 QList<int> aTopAbsTypes;
389 QList<int>::const_iterator it;
390 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
391 int topAbsMode = getTopAbsMode(*it);
392 if(topAbsMode != -1 )
393 aTopAbsTypes.append(topAbsMode);
395 aFilter->addSubTypes(aTopAbsTypes);
401 //================================================================
402 // Function : getEntry
404 //================================================================
405 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
407 SUIT_Session* session = SUIT_Session::session();
408 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
411 CORBA::String_var IOR = app->orb()->object_to_string( object );
412 if ( strcmp(IOR.in(), "") != 0 )
414 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
415 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
423 //================================================================
424 // Function : getName
426 //================================================================
427 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
429 SUIT_Session* session = SUIT_Session::session();
430 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
433 CORBA::String_var IOR = app->orb()->object_to_string( object );
434 if ( strcmp(IOR.in(), "") != 0 )
436 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
437 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
439 _PTR(GenericAttribute) anAttr;
441 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
443 _PTR(AttributeName) aNameAttr( anAttr );
444 return aNameAttr->Value();
452 //=================================================================
454 * GEOM_Displayer::GEOM_Displayer
457 //=================================================================
458 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
461 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
466 SUIT_Session* session = SUIT_Session::session();
467 SUIT_ResourceMgr* resMgr = session->resourceMgr();
469 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
470 myShadingColor = SalomeApp_Tools::color( col );
472 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
473 myHasDisplayMode = false;
475 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
477 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
478 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
479 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
481 // Next properties provide a way to customize displaying of presentations;
482 // for instance, this is useful for preview
492 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
495 // Activate parallel vizualisation only for testing purpose
496 // and if the corresponding env variable is set to 1
497 char* parallel_visu = getenv("PARALLEL_VISU");
498 if (parallel_visu && atoi(parallel_visu))
500 MESSAGE("Parallel visualisation on");
501 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
506 myFieldDataType = GEOM::FDT_Double;
507 myFieldDimension = 0;
508 myFieldStepRangeMin = 0;
509 myFieldStepRangeMax = 0;
512 //=================================================================
514 * GEOM_Displayer::~GEOM_Displayer
517 //=================================================================
518 GEOM_Displayer::~GEOM_Displayer()
522 //=================================================================
524 * GEOM_Displayer::Display
525 * Display interactive object in the current viewer
527 //=================================================================
528 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
529 const bool updateViewer,
530 SALOME_View* theViewFrame )
532 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
535 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
539 vf->BeforeDisplay( this, prs );
540 vf->Display( this, prs );
541 vf->AfterDisplay( this, prs );
546 delete prs; // delete presentation because displayer is its owner
551 //=================================================================
553 * GEOM_Displayer::Display
554 * This overloaded Display() method can be useful for operations
555 * not using dialog boxes.
557 //=================================================================
558 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
560 if ( theObj->_is_nil() )
563 std::string entry = getEntry( theObj );
565 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
570 //=================================================================
572 * GEOM_Displayer::Erase
573 * Erase interactive object in the current viewer
575 //=================================================================
576 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
578 const bool updateViewer,
579 SALOME_View* theViewFrame )
581 if ( theIO.IsNull() )
584 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
587 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
589 vf->BeforeErase( this, prs );
590 vf->Erase( this, prs, forced );
591 vf->AfterErase( this, prs );
594 delete prs; // delete presentation because displayer is its owner
599 //=================================================================
601 * GEOM_Displayer::Erase
602 * Erase geometry object in the current viewer
604 //=================================================================
605 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
607 const bool updateViewer,
608 SALOME_View* theViewFrame)
610 std::string entry = getEntry( theObj );
613 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
614 forced, updateViewer, theViewFrame);
618 //=================================================================
620 * GEOM_Displayer::Redisplay
621 * Redisplay (erase and then display again) interactive object
622 * in the current viewer
624 //=================================================================
625 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
626 const bool updateViewer,
627 const bool checkActiveViewer )
629 // Remove the object permanently (<forced> == true)
630 SUIT_Session* ses = SUIT_Session::session();
631 SUIT_Application* app = ses->activeApplication();
634 SUIT_Desktop* desk = app->desktop();
635 QList<SUIT_ViewWindow*> wnds = desk->windows();
636 SUIT_ViewWindow* wnd;
637 QListIterator<SUIT_ViewWindow*> it( wnds );
638 while ( it.hasNext() && (wnd = it.next()) )
640 SUIT_ViewManager* vman = wnd->getViewManager();
643 SUIT_ViewModel* vmodel = vman->getViewModel();
646 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
649 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
651 Redisplay( theIO, updateViewer, view );
660 //=================================================================
662 * GEOM_Displayer::Redisplay
663 * Redisplay (erase and then display again) interactive object
664 * in the specified view
666 //=================================================================
667 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
668 const bool theUpdateViewer,
669 SALOME_View* theViewFrame )
671 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
677 Erase( theIO, true, false, theViewFrame );
678 Display( theIO, theUpdateViewer, theViewFrame );
681 //=================================================================
683 * GEOM_Displayer::Display
684 * Calls Display() method for each object in the given list
686 //=================================================================
687 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
689 SALOME_ListIteratorOfListIO Iter( theIOList );
690 for ( ; Iter.More(); Iter.Next() ) {
691 Display( Iter.Value(), false );
697 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
699 SalomeApp_Study* aStudy = getStudy();
701 if ( v ) vId = getViewManagerId( v );
704 QString entry = p->GetEntry();
705 if ( !entry.isEmpty() ) {
707 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
708 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
713 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
718 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
720 // VSR: this method can be improved in future:
721 // to improve performance, the default values from resource manager should be cached in the displayer
722 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
725 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
727 // VSR: this method can be improved in future:
728 // to improve performance, the default values from resource manager should be cached in the displayer
729 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
732 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
734 // check that shape is not null
735 if ( AISShape.IsNull() ) return;
737 // check that study is active
738 SalomeApp_Study* study = getStudy();
739 if ( !study ) return;
741 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
742 !TopoDS_Iterator(myShape).More() )
743 return; // NPAL15983 (Bug when displaying empty groups)
745 // set interactive object
747 Handle( SALOME_InteractiveObject ) anIO;
749 if ( !myIO.IsNull() ) {
750 AISShape->setIO( myIO );
751 AISShape->SetOwner( myIO );
754 else if ( !myName.empty() ) {
755 // workaround to allow selection of temporary objects
756 static int tempId = 0;
757 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
758 AISShape->setIO( anIO );
759 AISShape->SetOwner( anIO );
762 // flag: only vertex or compound of vertices is processed (specific handling)
763 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
764 // presentation study entry (empty for temporary objects like preview)
765 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
766 // flag: temporary object
767 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
768 // currently active view window's ID (-1 if no active view)
769 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
771 // get presentation properties
772 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
774 // Temporary staff: vertex must be infinite for correct visualization
775 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
778 Material_Model material;
779 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
781 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
782 // - set front material properties
783 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
784 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
785 // - set back material properties
786 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
787 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
788 // - switch to default (both sides) facing mode
789 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
795 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
796 // we set it to the shape not taking into account material properties
797 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
799 else if ( !material.isPhysical() ) {
800 // shading color from properties is used only for non-physical materials
801 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
805 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
806 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
807 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
808 AISShape->Attributes()->SetLineAspect( anAspect );
810 // - unfree boundaries color
811 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
812 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
813 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
814 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
816 // - free boundaries color
817 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
818 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
819 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
820 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
822 // - standalone edges color
823 anAspect = AISShape->Attributes()->WireAspect();
824 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
825 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
826 AISShape->Attributes()->SetWireAspect( anAspect );
828 // - color for edges in shading+edges mode
829 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
832 AISShape->SetDisplayMode( HasDisplayMode() ?
833 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
835 // display mode from properties
836 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
838 // - face boundaries color
839 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
840 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
841 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
842 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
843 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
845 // set display vectors flag
846 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
848 // set display vertices flag
849 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
850 AISShape->SetDisplayVertices( isVerticesMode );
853 if( HasTransparency() ) {
854 AISShape->SetTransparency( GetTransparency() );
856 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
859 // set iso properties
860 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
861 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
862 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
863 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
864 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
865 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
867 if ( HasIsosColor() ) {
868 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
869 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
872 uIsoAspect->SetColor( isosColor );
873 vIsoAspect->SetColor( isosColor );
876 if ( HasIsosWidth() ) {
877 uIsoAspect->SetWidth( GetIsosWidth() );
878 vIsoAspect->SetWidth( GetIsosWidth() );
881 uIsoAspect->SetWidth( isosWidth );
882 vIsoAspect->SetWidth( isosWidth );
886 uIsoAspect->SetNumber( GetNbIsos() );
887 vIsoAspect->SetNumber( GetNbIsos() );
890 uIsoAspect->SetNumber( uIsos );
891 vIsoAspect->SetNumber( vIsos );
894 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
895 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
897 // set deflection coefficient
898 // ... to avoid to small values of the coefficient, its lower value is limited
899 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
903 if ( HasTexture() ) {
904 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
905 aImagePath = GetTexture().c_str();
906 if ( ! entry.isEmpty() ) {
907 // check that study is active
908 SalomeApp_Study* study = getActiveStudy();
910 // Store the texture in object properties for next displays
911 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
912 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
914 // Update propeties map
915 propMap = getObjectProperties( study, entry, myViewFrame );
920 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
923 #ifdef USE_TEXTURED_SHAPE
924 Handle(Image_PixMap) aPixmap;
925 if ( !aImagePath.isEmpty() )
926 aPixmap = cacheTextureFor( aImagePath, AISShape );
928 aPixmap = getDefaultTexture();
930 // apply image to shape
931 if ( !aPixmap.IsNull() ) {
932 AISShape->SetTexturePixMap( aPixmap );
933 AISShape->SetTextureMapOn();
934 AISShape->DisableTextureModulate();
937 AISShape->SetTextureMapOff();
942 AISShape->SetWidth( HasWidth() ?
943 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
945 // libe width from properties
946 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
948 // set top-level flag
949 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
951 // set point marker (for vertex / compound of vertices only)
952 if ( onlyVertex || isVerticesMode ) {
953 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
954 if ( aList.size() == 2 ) {
955 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
956 int aTypeOfMarker = aList[0].toInt();
957 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
958 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
959 anAspect->SetScale( aScaleOfMarker );
960 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
961 anAspect->SetColor( HasColor() ?
962 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
963 (Quantity_NameOfColor)GetColor() :
964 // color from properties
965 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
966 AISShape->Attributes()->SetPointAspect( anAspect );
968 else if ( aList.size() == 1 ) {
969 // custom marker string contains "IdOfTexture"
970 int textureId = aList[0].toInt();
971 Standard_Integer aWidth, aHeight;
972 Handle(TColStd_HArray1OfByte) aTexture =
973 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
974 if ( !aTexture.IsNull() ) {
975 Handle(Prs3d_PointAspect) aTextureAspect =
976 new Prs3d_PointAspect( HasColor() ?
977 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
978 (Quantity_NameOfColor)GetColor() :
979 // color from properties
980 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
983 AISShape->Attributes()->SetPointAspect( aTextureAspect );
988 // set field step data
989 AISShape->setFieldStepInfo( myFieldDataType,
994 myFieldStepRangeMax );
996 if ( create && !isTemporary && aMgrId != -1 ) {
997 // set properties to the study
998 study->setObjectProperties( aMgrId, entry, propMap );
1001 // AISShape->SetName(???); ??? necessary to set name ???
1004 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1006 // check that actor is not null
1007 if ( !actor ) return;
1009 // check that study is active
1010 SalomeApp_Study* study = getStudy();
1011 if ( !study ) return;
1013 // set interactive object
1015 Handle( SALOME_InteractiveObject ) anIO;
1017 if ( !myIO.IsNull() ) {
1018 actor->setIO( myIO );
1021 else if ( !myName.empty() ) {
1022 // workaround to allow selection of temporary objects
1023 static int tempId = 0;
1024 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1025 actor->setIO( anIO );
1028 // presentation study entry (empty for temporary objects like preview)
1029 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1030 // flag: temporary object
1031 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1032 // currently active view window's ID (-1 if no active view)
1033 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1035 // get presentation properties
1036 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1039 /////////////////////////////////////////////////////////////////////////
1040 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1041 // due to performance problem
1042 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1043 /////////////////////////////////////////////////////////////////////////
1044 if ( !actor->getTopo().IsSame( myShape ) )
1045 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1048 Material_Model material;
1049 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1050 std::vector<vtkProperty*> mprops;
1051 mprops.push_back( material.getMaterialVTKProperty( true ) );
1052 mprops.push_back( material.getMaterialVTKProperty( false) );
1053 actor->SetMaterial( mprops );
1055 // set iso-lines properties
1057 // - set number of iso-lines
1058 int nbIsos[2]= { 1, 1 };
1059 if ( HasNbIsos() ) {
1060 nbIsos[0] = GetNbIsos();
1061 nbIsos[1] = GetNbIsos();
1064 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1065 nbIsos[0] = isos[0].toInt();
1066 nbIsos[1] = isos[1].toInt();
1068 actor->SetNbIsos( nbIsos );
1070 // - set iso-lines width
1071 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1073 // - set iso-lines color
1074 if ( HasIsosColor() )
1075 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1077 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1078 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1083 // - same color for all sub-actors
1084 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1085 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1088 // shading color (for non-physical materials)
1089 if ( !material.isPhysical() ) {
1090 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1091 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1092 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1095 // - standalone edge color
1096 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1097 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1099 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1100 // - shared edges color ???
1101 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1103 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1104 // - free edges color ???
1105 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1108 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1109 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1112 // - color for edges in shading+edges mode
1113 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1114 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1117 if( HasTransparency() ) {
1118 actor->SetOpacity( 1.0 - GetTransparency() );
1120 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1124 actor->SetWidth( HasWidth() ?
1125 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1127 // libe width from properties
1128 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1130 // set display vectors flag
1131 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1133 // set display vertices flag
1134 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1137 int displayMode = HasDisplayMode() ?
1138 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1140 // display mode from properties
1141 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1143 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1144 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1145 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1146 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1148 if ( displayMode == 2 )
1149 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1150 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1152 actor->setDisplayMode( displayMode );
1155 actor->PickableOn();
1157 actor->PickableOff();
1159 if ( create && !isTemporary && aMgrId != -1 ) {
1160 // set properties to the study
1161 study->setObjectProperties( aMgrId, entry, propMap );
1165 //=================================================================
1167 * GEOM_Displayer::updateDimensions
1168 * Creates or renews dimension presentation for the IO.
1170 //=================================================================
1171 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1172 SALOME_OCCPrs* thePrs,
1173 const gp_Ax3& theShapeLCS )
1175 SalomeApp_Study* aStudy = getStudy();
1181 if ( theIO.IsNull() )
1186 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1188 AIS_ListOfInteractive aListOfIO;
1190 anOccPrs->GetObjects( aListOfIO );
1192 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1194 // remove outdated presentations of dimensions
1195 for ( ; aIterateIO.More(); aIterateIO.Next() )
1197 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1198 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1203 aListOfIO.Remove( aIterateIO );
1205 if ( !aIterateIO.More() )
1211 // prepare dimension styling
1212 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1214 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1215 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1216 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1217 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1218 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1219 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1220 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1222 // restore dimension presentation from saved attribute or property data
1223 AIS_ListOfInteractive aRestoredDimensions;
1225 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1227 GEOM::propertyName( GEOM::Dimensions ),
1230 GEOMGUI_DimensionProperty aRecords;
1232 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1234 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1238 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1241 // create up-to-date dimension presentations
1242 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1244 if ( !aRecords.IsVisible( aPrsIt ) )
1249 // init dimension by type
1250 Handle(AIS_Dimension) aPrs;
1251 switch( aRecords.GetType( aPrsIt ) )
1253 case GEOMGUI_DimensionProperty::DimensionType_Length :
1255 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1256 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1261 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1263 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1264 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1269 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1271 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1272 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1278 aPrs->SetOwner( theIO );
1280 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1282 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1284 aStyle->SetCommonColor( aColor );
1285 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1286 aStyle->MakeText3d( Standard_True );
1287 aStyle->MakeTextShaded( Standard_True );
1288 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1289 aStyle->TextAspect()->SetHeight( aFontHeight );
1290 aStyle->ArrowAspect()->SetLength( anArrowLength );
1291 aStyle->LineAspect()->SetWidth( aLineWidth );
1292 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1293 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1294 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1295 aPrs->SetDimensionAspect( aStyle );
1296 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1297 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1298 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1300 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1302 // show degree symbol for dimension instead of label "deg"
1303 if ( aUnitsAngle == "deg" )
1305 aPrs->SetSpecialSymbol(0xB0);
1306 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1307 aStyle->MakeUnitsDisplayed(Standard_False);
1311 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1312 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1317 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1320 aListOfIO.Append( aPrs );
1323 // update presentation
1326 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1328 anOccPrs->AddObject( aIterateIO.Value() );
1332 //=================================================================
1334 * GEOM_Displayer::Erase
1335 * Calls Erase() method for each object in the given list
1337 //=================================================================
1338 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1340 const bool updateViewer )
1342 SALOME_ListIteratorOfListIO Iter( theIOList );
1343 for ( ; Iter.More(); Iter.Next() )
1344 Erase( Iter.Value(), forced, false );
1350 //=================================================================
1352 * GEOM_Displayer::Redisplay
1353 * Calls Redisplay() method for each object in the given list
1355 //=================================================================
1356 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1357 const bool updateViewer,
1358 const bool checkActiveViewer )
1360 SALOME_ListIteratorOfListIO Iter( theIOList );
1361 for ( ; Iter.More(); Iter.Next() )
1362 Redisplay( Iter.Value(), false, checkActiveViewer );
1368 //=================================================================
1370 * GEOM_Displayer::Redisplay
1371 * Calls Redisplay() method for each object in the given list
1373 //=================================================================
1374 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1375 const bool theUpdateViewer,
1376 SALOME_View* theViewFrame )
1378 SALOME_ListIteratorOfListIO anIter( theIOList );
1379 for ( ; anIter.More(); anIter.Next() )
1381 Redisplay( anIter.Value(), false, theViewFrame );
1384 if ( theUpdateViewer )
1390 //=================================================================
1392 * GEOM_Displayer::Update
1393 * Update OCC presentaion
1394 * [ Reimplemented from SALOME_Displayer ]
1396 //=================================================================
1397 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1399 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1400 SalomeApp_Study* study = getStudy();
1402 if ( !occPrs || myShape.IsNull() || !study )
1405 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1408 // specific processing for local coordinate system presentation
1411 TopoDS_Face aFace = TopoDS::Face( myShape );
1412 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1413 if ( !aPlane.IsNull() )
1415 gp_Ax3 aPos = aPlane->Pln().Position();
1416 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1418 Handle(GEOM_AISTrihedron) aTrh;
1420 if ( occPrs->IsNull() )
1422 // new presentation is being created
1423 aTrh = new GEOM_AISTrihedron( aPlc );
1424 occPrs->AddObject( aTrh );
1428 // presentation is being updated
1429 AIS_ListOfInteractive aList;
1430 occPrs->GetObjects( aList );
1431 AIS_ListIteratorOfListOfInteractive anIter( aList );
1432 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1433 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1437 if ( !aTrh.IsNull() ) {
1438 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1440 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1441 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1443 aTrh->SetWidth( GetWidth() );
1445 if ( !myIO.IsNull() )
1447 aTrh->setIO( myIO );
1448 aTrh->SetOwner( myIO );
1450 aTrh->SetComponent( aPlc );
1451 aTrh->SetToUpdate();
1453 occPrs->SetToActivate( ToActivate() );
1459 // processing for usual geometry presentation
1462 // if presentation is empty we try to create new one
1463 if ( occPrs->IsNull() )
1465 // create presentation (specific for vectors)
1466 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1467 : new GEOM_AISShape ( myShape, "" );
1469 if( myType == GEOM_FIELD_STEP )
1470 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1471 // update shape properties
1472 updateShapeProperties( AISShape, true );
1474 // add shape to the presentation
1475 occPrs->AddObject( AISShape );
1477 // In accordance with ToActivate() value object will be activated/deactivated
1478 // when it will be displayed
1479 occPrs->SetToActivate( ToActivate() );
1481 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1482 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1484 // create additional wireframe shape
1485 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1486 aWirePrs->SetWidth(AISShape->Width());
1487 if ( !myIO.IsNull() ) {
1488 aWirePrs->setIO( myIO );
1489 aWirePrs->SetOwner( myIO );
1492 // add shape to the presentation
1493 occPrs->AddObject( aWirePrs );
1496 // if presentation is found -> set again shape for it
1499 AIS_ListOfInteractive IOList;
1500 occPrs->GetObjects( IOList );
1501 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1502 for ( ; Iter.More(); Iter.Next() )
1504 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1505 if ( AISShape.IsNull() )
1508 // re-set shape (it might be changed)
1509 if ( AISShape->Shape() != myShape )
1510 AISShape->Set( myShape );
1512 // update shape properties
1513 updateShapeProperties( AISShape, false );
1516 AISShape->UpdateSelection();
1517 AISShape->SetToUpdate();
1521 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1525 //=================================================================
1527 * GEOM_Displayer::Update
1528 * Update VTK presentaion
1529 * [ Reimplemented from SALOME_Displayer ]
1531 //=================================================================
1532 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1534 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1535 SalomeApp_Study* study = getStudy();
1537 if ( !vtkPrs || myShape.IsNull() || !study )
1540 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1543 // specific processing for local coordinate system presentation
1546 TopoDS_Face aFace = TopoDS::Face( myShape );
1547 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1548 if ( !aPlane.IsNull() ) {
1549 gp_Ax3 aPos = aPlane->Pln().Position();
1550 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1552 GEOM_VTKTrihedron* aTrh = 0;
1554 if ( vtkPrs->IsNull() ) {
1555 // new presentation is being created
1556 aTrh = GEOM_VTKTrihedron::New();
1557 vtkPrs->AddObject( aTrh );
1560 // presentation is being updated
1561 vtkActorCollection* actors = vtkPrs->GetObjects();
1563 actors->InitTraversal();
1564 vtkActor* a = actors->GetNextActor();
1565 while ( a && !aTrh ) {
1566 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1567 a = actors->GetNextActor();
1573 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1575 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1576 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1578 #ifdef VTK_TRIHEDRON_WIDTH
1580 // VSR: currently isn't supported
1582 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1584 aTrh->SetWidth( GetWidth() );
1587 if ( !myIO.IsNull() )
1588 aTrh->setIO( myIO );
1590 aTrh->SetPlacement( aPlc );
1597 // processing for usual geometry presentation
1600 // if presentation is empty we try to create new one
1601 if ( vtkPrs->IsNull() )
1604 GEOM_Actor* actor = GEOM_Actor::New();
1605 // update actor properties
1606 updateActorProperties( actor, true );
1607 // add actor to the presentation
1608 vtkPrs->AddObject( actor );
1611 // presentation is being updated
1612 vtkActorCollection* actors = vtkPrs->GetObjects();
1614 actors->InitTraversal();
1615 vtkActor* a = actors->GetNextActor();
1617 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1619 // update actor properties
1620 updateActorProperties( actor, false );
1621 a = actors->GetNextActor();
1629 //=================================================================
1631 * GEOM_Displayer::BuildPrs
1632 * Build presentation accordint to the current viewer type
1634 //=================================================================
1635 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1637 if ( theObj->_is_nil() )
1640 myViewFrame = GetActiveView();
1641 if ( myViewFrame == 0 )
1644 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1649 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1650 myType = theObj->GetType();
1652 // Update presentation
1658 //=================================================================
1660 * GEOM_Displayer::BuildPrs
1661 * Build presentation accordint to the current viewer type
1663 //=================================================================
1664 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1666 myViewFrame = GetActiveView();
1667 if ( theShape.IsNull() || myViewFrame == 0 )
1670 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1675 setShape( theShape );
1683 //=================================================================
1685 * GEOM_Displayer::buildPresentation
1686 * Builds/finds object's presentation for the current viewer
1687 * Calls corresponding Update() method by means of double dispatch
1690 //=================================================================
1691 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1692 SALOME_View* theViewFrame )
1694 SALOME_Prs* prs = 0;
1697 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1701 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1704 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1705 theIO->setEntry( entry.toLatin1().constData() );
1706 if ( !theIO.IsNull() )
1708 // set interactive object
1710 // Find SOBject (because shape should be published previously)
1711 SUIT_Session* session = SUIT_Session::session();
1712 SUIT_Application* app = session->activeApplication();
1715 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1718 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1721 // get CORBA reference to data object
1722 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1723 if ( !CORBA::is_nil( object ) )
1725 // downcast to GEOM base object
1726 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1727 if ( !GeomBaseObject->_is_nil() )
1729 myType = GeomBaseObject->GetType();
1731 // downcast to GEOM object
1732 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1733 if ( myType == GEOM_FIELD_STEP )
1735 // get the GEOM object from the field's shape
1736 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1737 if ( !GeomFieldStep->_is_nil() )
1739 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1740 if ( !GeomField->_is_nil() )
1741 GeomObject = GeomField->GetShape();
1744 // read the field step information
1745 readFieldStepInfo( GeomFieldStep );
1748 if ( !GeomObject->_is_nil() )
1750 // finally set shape
1751 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1759 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1765 //=================================================================
1767 * GEOM_Displayer::buildSubshapePresentation
1768 * Builds/finds object's presentation for the current viewer
1769 * Calls corresponding Update() method by means of double dispatch
1770 * For not published objects (for Mantis issue 0020435)
1772 //=================================================================
1773 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1774 const QString& entry,
1775 SALOME_View* theViewFrame)
1777 SALOME_Prs* prs = 0;
1780 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1784 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1787 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1788 theIO->setEntry(entry.toLatin1().constData());
1789 if (!theIO.IsNull())
1791 // set interactive object
1793 // finally set shape
1795 myType = GEOM_SUBSHAPE;
1797 UpdatePrs(prs); // Update presentation by using of the double dispatch
1803 //=================================================================
1805 * GEOM_Displayer::internalReset
1806 * Resets internal data
1809 //=================================================================
1810 void GEOM_Displayer::internalReset()
1815 myFieldDataType = GEOM::FDT_Double;
1816 myFieldDimension = 0;
1817 myFieldStepData.clear();
1818 myFieldStepName.Clear();
1819 myFieldStepRangeMin = 0;
1820 myFieldStepRangeMax = 0;
1823 //=================================================================
1825 * GEOM_Displayer::LocalSelection
1826 * Activate selection of CAD shapes with activisation of selection
1827 * of their sub-shapes (with opened local context for OCC viewer)
1829 //=================================================================
1830 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1832 SUIT_Session* session = SUIT_Session::session();
1833 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1837 LightApp_SelectionMgr* sm = app->selectionMgr();
1839 // remove all filters from selection
1842 SALOME_View* vf = GetActiveView();
1844 if (!theIO.IsNull() && !vf->isVisible(theIO))
1846 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1847 vf->LocalSelection( prs, theMode );
1848 delete prs; // delete presentation because displayer is its owner
1852 //=================================================================
1854 * GEOM_Displayer::globalSelection
1855 * Activate selection of CAD shapes without activisation of selection
1856 * of their sub-shapes (without opened local context for OCC viewer)
1858 //=================================================================
1859 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1861 TColStd_MapOfInteger aModes;
1862 aModes.Add( theMode );
1863 GlobalSelection( aModes, update );
1866 //=================================================================
1868 * GEOM_Displayer::globalSelection
1869 * Activate selection of CAD shapes without activisation of selection
1870 * of their sub-shapes (without opened local context for OCC viewer)
1872 //=================================================================
1873 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1874 const bool update, const QList<int>* theSubShapes )
1876 SUIT_Session* session = SUIT_Session::session();
1877 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1881 SALOME_View* vf = GetActiveView();
1885 // Close local context
1886 vf->GlobalSelection( update );
1888 // Set selection filters in accordance with current mode
1889 LightApp_SelectionMgr* sm = app->selectionMgr();
1893 // Remove from selection temporary objects if necessary
1894 if ( !theModes.Contains( GEOM_PREVIEW ) )
1895 clearTemporary( sm );
1897 //@ aSel->ClearIndex();
1901 // Remove filters from AIS_InteractiveContext
1902 Handle(AIS_InteractiveContext) ic;
1903 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1906 ic = viewer->getAISContext();
1908 ic->RemoveFilters();
1911 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1914 SUIT_SelectionFilter* aFilter;
1915 if ( theModes.Extent() == 1 )
1917 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1919 if ( aMode == GEOM_COMPOUNDFILTER )
1920 aFilter = getComplexFilter( theSubShapes );
1922 aFilter = getFilter( aMode );
1924 else if ( theModes.Extent() > 1 )
1926 TColStd_MapOfInteger aTopAbsModes;
1927 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1928 QList<SUIT_SelectionFilter*> aListOfFilters;
1929 for ( ; anIter.More(); anIter.Next() )
1931 SUIT_SelectionFilter* aFilter;
1932 int aMode = anIter.Key();
1933 if ( aMode == GEOM_COMPOUNDFILTER )
1934 aFilter = getComplexFilter( theSubShapes );
1936 aFilter = getFilter( aMode );
1939 aListOfFilters.append( aFilter );
1942 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1949 sm->installFilter( aFilter );
1952 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1953 ic->AddFilter( anOCCFilter );
1958 //=================================================================
1960 * GEOM_Displayer::LocalSelection
1961 * Activate selection of CAD shapes with activisation of selection
1962 * of their sub-shapes (with opened local context for OCC viewer)
1964 //=================================================================
1965 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1967 SALOME_ListIteratorOfListIO Iter( theIOList );
1968 for ( ; Iter.More(); Iter.Next() )
1969 LocalSelection( Iter.Value(), theMode );
1972 //=================================================================
1974 * GEOM_Displayer::BeforeDisplay
1975 * Called before displaying of pars. Close local context
1976 * [ Reimplemented from SALOME_Displayer ]
1978 //=================================================================
1979 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1981 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1984 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1987 if ( ic->HasOpenedContext() )
1988 ic->CloseAllContexts();
1993 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
1995 UpdateColorScale(false,false);
1998 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2000 LightApp_Displayer::BeforeErase( v, p );
2001 releaseTextures( p );
2004 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2006 LightApp_Displayer::AfterErase( v, p );
2007 UpdateColorScale(false,false);
2010 //=================================================================
2012 * GEOM_Displayer::SetColor
2013 * Set color for shape displaying. If it is equal -1 then default color is used.
2014 * Available values are from Quantity_NameOfColor enumeration
2016 //=================================================================
2017 void GEOM_Displayer::SetColor( const int color )
2024 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2028 int GEOM_Displayer::GetColor() const
2033 bool GEOM_Displayer::HasColor() const
2035 return myColor != -1;
2038 void GEOM_Displayer::UnsetColor()
2042 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2043 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2044 myShadingColor = SalomeApp_Tools::color( col );
2047 //=================================================================
2049 * GEOM_Displayer::SetTransparency
2050 * Set transparency for shape displaying.
2052 //=================================================================
2053 double GEOM_Displayer::SetTransparency( const double transparency )
2055 double prevTransparency = myTransparency;
2056 myTransparency = transparency;
2057 return prevTransparency;
2060 //=================================================================
2062 * GEOM_Displayer::GetTransparency
2063 * Get transparency for shape displaying.
2065 //=================================================================
2066 double GEOM_Displayer::GetTransparency() const
2068 return myTransparency;
2071 //=================================================================
2073 * GEOM_Displayer::HasTransparency
2074 * Check if transparency for shape displaying is set.
2076 //=================================================================
2077 bool GEOM_Displayer::HasTransparency() const
2079 return myTransparency >= 0;
2082 //=================================================================
2084 * GEOM_Displayer::UnsetTransparency
2085 * Unset transparency for shape displaying.
2087 //=================================================================
2088 double GEOM_Displayer::UnsetTransparency()
2090 return SetTransparency( -1 );
2093 //=================================================================
2095 * GEOM_Displayer::SetTexture
2097 //=================================================================
2098 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2100 myTexture = texureFileName;
2103 bool GEOM_Displayer::HasTexture() const
2105 return myTexture != "";
2108 std::string GEOM_Displayer::GetTexture() const
2113 //=================================================================
2115 * GEOM_Displayer::SetWidth
2116 * Set width of shape displaying. If it is equal -1 then default width is used.
2118 //=================================================================
2119 void GEOM_Displayer::SetWidth( const double width )
2124 double GEOM_Displayer::GetWidth() const
2129 bool GEOM_Displayer::HasWidth() const
2131 return myWidth != -1;
2134 void GEOM_Displayer::UnsetWidth()
2139 int GEOM_Displayer::GetIsosWidth() const
2144 void GEOM_Displayer::SetIsosWidth(const int width)
2146 myIsosWidth = width;
2149 bool GEOM_Displayer::HasIsosWidth() const
2151 return myIsosWidth != -1;
2154 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2156 int prevNbIsos = myNbIsos;
2161 int GEOM_Displayer::UnsetNbIsos()
2163 return SetNbIsos( -1 );
2166 int GEOM_Displayer::GetNbIsos() const
2171 bool GEOM_Displayer::HasNbIsos() const
2173 return myNbIsos >= 0;
2176 int GEOM_Displayer::SetIsosColor( const int color )
2178 int prevColor = myIsosColor;
2179 myIsosColor = color;
2183 int GEOM_Displayer::GetIsosColor() const
2188 bool GEOM_Displayer::HasIsosColor() const
2190 return myIsosColor != -1;
2193 int GEOM_Displayer::UnsetIsosColor()
2195 return SetIsosColor( -1 );
2198 //=================================================================
2200 * GEOM_Displayer::SetToActivate
2201 * This method is used for activisation/deactivisation of objects to be displayed
2203 //=================================================================
2204 void GEOM_Displayer::SetToActivate( const bool toActivate )
2206 myToActivate = toActivate;
2208 bool GEOM_Displayer::ToActivate() const
2210 return myToActivate;
2213 //=================================================================
2215 * GEOM_Displayer::clearTemporary
2216 * Removes from selection temporary objects
2218 //=================================================================
2219 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2221 SALOME_ListIO selected, toSelect;
2222 theSelMgr->selectedObjects( selected );
2224 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2225 Handle(SALOME_InteractiveObject) io = it.Value();
2226 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2227 toSelect.Append( it.Value() );
2230 theSelMgr->setSelectedObjects( toSelect, true );
2233 void GEOM_Displayer::SetName( const char* theName )
2238 void GEOM_Displayer::UnsetName()
2243 SalomeApp_Study* GEOM_Displayer::getStudy() const
2245 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2248 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2253 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2258 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2259 const int theFieldDimension,
2260 const QList<QVariant>& theFieldStepData,
2261 const TCollection_AsciiString& theFieldStepName,
2262 const double theFieldStepRangeMin,
2263 const double theFieldStepRangeMax )
2265 myFieldDataType = theFieldDataType;
2266 myFieldDimension = theFieldDimension;
2267 myFieldStepData = theFieldStepData;
2268 myFieldStepName = theFieldStepName;
2269 myFieldStepRangeMin = theFieldStepRangeMin;
2270 myFieldStepRangeMax = theFieldStepRangeMax;
2273 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2275 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2276 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2277 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2278 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2279 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2280 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2283 int GEOM_Displayer::SetDisplayMode( const int theMode )
2285 int aPrevMode = myDisplayMode;
2286 if ( theMode != -1 ) {
2287 myDisplayMode = theMode;
2288 myHasDisplayMode = true;
2296 int GEOM_Displayer::GetDisplayMode() const
2298 return myDisplayMode;
2301 int GEOM_Displayer::UnsetDisplayMode()
2303 int aPrevMode = myDisplayMode;
2304 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2305 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2306 myHasDisplayMode = false;
2310 bool GEOM_Displayer::HasDisplayMode() const
2312 return myHasDisplayMode;
2315 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2317 static QList<QColor> colors;
2319 if ( colors.isEmpty() ) {
2321 for (int s = 0; s < 2 ; s++)
2323 for (int v = 100; v >= 40; v = v - 20)
2325 for (int h = 0; h < 359 ; h = h + 60)
2327 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2333 static int currentColor = randomize( colors.size() );
2335 SALOMEDS::Color color;
2336 color.R = (double)colors[currentColor].red() / 255.0;
2337 color.G = (double)colors[currentColor].green() / 255.0;
2338 color.B = (double)colors[currentColor].blue() / 255.0;
2340 currentColor = (currentColor+1) % colors.count();
2345 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2348 int aTolerance = 64;
2349 int anIterations = 0;
2355 if( anIterations % aPeriod == 0 )
2358 if( aTolerance < 1 )
2361 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2363 aHue = (int)( 360.0 * rand() / RAND_MAX );
2364 //std::cout << "Hue = " << aHue << std::endl;
2366 //std::cout << "Auto colors : ";
2368 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2369 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2370 for( ; it != itEnd; ++it )
2372 SALOMEDS::Color anAutoColor = *it;
2373 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2376 aQColor.getHsv( &h, &s, &v );
2377 //std::cout << h << " ";
2378 if( abs( h - aHue ) < aTolerance )
2381 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2385 //std::cout << std::endl;
2391 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2393 aColor.setHsv( aHue, 255, 255 );
2395 SALOMEDS::Color aSColor;
2396 aSColor.R = (double)aColor.red() / 255.0;
2397 aSColor.G = (double)aColor.green() / 255.0;
2398 aSColor.B = (double)aColor.blue() / 255.0;
2403 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2404 const QString& entry,
2407 // get default properties for the explicitly specified default view type
2408 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2410 if ( study && view ) {
2411 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2412 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2413 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2415 if ( viewModel && viewId != -1 ) {
2416 // get properties from the study
2417 PropMap storedMap = study->getObjectProperties( viewId, entry );
2418 // overwrite default properties from stored ones (that are specified)
2419 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2420 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2421 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2422 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2424 // ... specific processing for color
2425 // ... current implementation is to use same stored color for all aspects
2426 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2427 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2428 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2429 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2430 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2431 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2432 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2435 if ( !entry.isEmpty() ) {
2436 // get CORBA reference to geom object
2437 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2439 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2440 if ( !CORBA::is_nil( object ) ) {
2441 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2442 if ( !CORBA::is_nil( geomObject ) ) { // to check
2443 // check that geom object has color properly set
2444 bool hasColor = false;
2445 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2446 // set color from geometry object (only once, if it is not yet set in GUI)
2447 // current implementation is to use same color for all aspects
2448 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2449 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2450 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2451 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2452 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2453 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2454 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2455 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2457 // check that object has point marker properly set
2458 GEOM::marker_type mType = geomObject->GetMarkerType();
2459 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2460 int mTextureId = geomObject->GetMarkerTexture();
2461 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2462 ( mType == GEOM::MT_USER && mTextureId > 0 );
2463 // set point marker from geometry object (only once, if it is not yet set in GUI)
2464 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2465 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2467 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2468 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2470 else if ( mType == GEOM::MT_USER ) {
2472 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2484 PropMap GEOM_Displayer::getDefaultPropertyMap()
2488 // get resource manager
2489 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2491 // fill in the properties map with default values
2493 // - visibility (false by default)
2494 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2496 // - nb isos (take default value from preferences)
2497 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2498 QString( "%1%2%3" ).
2499 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2500 arg( GEOM::subSectionSeparator() ).
2501 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2503 // - transparency (opacity = 1-transparency)
2504 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2505 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2507 // - display mode (take default value from preferences)
2508 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2509 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2511 // - show edges direction flag (false by default)
2512 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2514 // - show vertices flag (false by default)
2515 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2517 // - shading color (take default value from preferences)
2518 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2519 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2521 // - wireframe color (take default value from preferences)
2522 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2523 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2525 // - standalone edges color (take default value from preferences)
2526 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2527 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2529 // - free boundaries color (take default value from preferences)
2530 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2531 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2533 // - points color (take default value from preferences)
2534 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2535 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2537 // - isos color (take default value from preferences)
2538 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2539 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2541 // - outlines color (take default value from preferences)
2542 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2543 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2545 // - deflection coefficient (take default value from preferences)
2546 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2547 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2549 // - material (take default value from preferences)
2550 Material_Model material;
2551 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2552 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2554 // - edge width (take default value from preferences)
2555 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2556 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2558 // - isos width (take default value from preferences)
2559 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2560 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2562 // - point marker (take default value from preferences)
2563 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2564 QString( "%1%2%3" ).
2565 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2566 arg( GEOM::subSectionSeparator() ).
2567 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2569 // - top-level flag (false by default)
2570 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2575 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2576 SALOMEDS::Color aSColor;
2579 SUIT_Session* session = SUIT_Session::session();
2580 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2582 if ( app && !theGeomObject->_is_nil()) {
2583 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2586 _PTR(Study) aStudy = study->studyDS();
2587 aSColor = theGeomObject->GetColor();
2588 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2590 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2591 bool general_autocolor = true;
2592 #else // auto-color for groups only
2593 bool general_autocolor = false;
2594 #endif // GENERAL_AUTOCOLOR
2595 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2596 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2597 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2598 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2599 aSColor = getPredefinedUniqueColor();
2601 #else // old algorithm for auto-colors
2602 QList<SALOMEDS::Color> aReservedColors;
2603 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2604 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2605 if ( aMainSObject ) {
2606 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2607 for ( ; it->More(); it->Next() ) {
2608 _PTR(SObject) aChildSObject( it->Value() );
2609 GEOM::GEOM_Object_var aChildObject =
2610 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2611 if ( CORBA::is_nil( aChildObject ) )
2614 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2615 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2616 aReservedColors.append( aReservedColor );
2619 aSColor = getUniqueColor( aReservedColors );
2621 #endif // SIMPLE_AUTOCOLOR
2631 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2632 const bool eraseOnlyChildren) {
2633 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2637 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2641 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2646 // Erase from all views
2647 QList<SALOME_View*> views;
2649 ViewManagerList vmans = app->viewManagers();
2650 SUIT_ViewManager* vman;
2651 foreach ( vman, vmans ) {
2652 SUIT_ViewModel* vmod = vman->getViewModel();
2653 view = dynamic_cast<SALOME_View*> ( vmod );
2655 views.append( view );
2658 if( views.count() == 0 )
2661 //Erase childrens w/o update views
2662 DataObjectList listObj = parent->children( true );
2663 SUIT_DataObject* obj;
2664 foreach( obj, listObj ) {
2665 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2667 foreach ( view, views ) {
2668 Handle(SALOME_InteractiveObject) anIO =
2669 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2670 Erase(anIO, false, false, view);
2674 //Erase parent with view update or repaint views
2675 foreach ( view, views ) {
2676 if(!eraseOnlyChildren)
2677 Erase(theIO, false, true, view);
2683 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2685 if( theGeomFieldStep->_is_nil() )
2688 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2689 if( aGeomField->_is_nil() )
2692 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2693 if( aGeomFieldShape->_is_nil() )
2696 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2697 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2698 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2700 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2702 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2704 int aFieldDimension = aGeomField->GetDimension();
2706 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2707 int aFieldNbComponents = aFieldComponents->length();
2709 QList<QVariant> aFieldStepData;
2710 if( aFieldDataType == GEOM::FDT_Bool )
2712 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2713 if ( !aGeomBoolFieldStep->_is_nil() )
2715 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2716 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2717 aFieldStepData << (bool)aValues[i];
2720 else if( aFieldDataType == GEOM::FDT_Int )
2722 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2723 if ( !aGeomIntFieldStep->_is_nil() )
2725 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2726 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2727 aFieldStepData << (qlonglong)aValues[i];
2730 else if( aFieldDataType == GEOM::FDT_Double )
2732 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2733 if ( !aGeomDoubleFieldStep->_is_nil() )
2735 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2736 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2737 aFieldStepData << (double)aValues[i];
2740 else if( aFieldDataType == GEOM::FDT_String )
2742 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2743 if ( !aGeomStringFieldStep->_is_nil() )
2745 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2746 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2747 aFieldStepData << QString( aValues[i] );
2751 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2752 aFieldStepData = groupFieldData( aFieldStepData,
2754 aFieldDataType == GEOM::FDT_String,
2756 aFieldStepRangeMax );
2758 setFieldStepInfo( aFieldDataType,
2763 aFieldStepRangeMax );
2766 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2767 const int theFieldNbComponents,
2768 const bool theIsString,
2769 double& theFieldStepRangeMin,
2770 double& theFieldStepRangeMax )
2772 QList<QVariant> aResultList;
2773 theFieldStepRangeMin = 0;
2774 theFieldStepRangeMax = 0;
2776 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2779 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2781 QList<QVariant> aGroupedList;
2783 bool anIsBoolean = false;
2784 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2787 QStringList aStringList;
2789 int aBaseIndex = aSubShape * theFieldNbComponents;
2790 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2792 int anIndex = aComponent + aBaseIndex;
2794 const QVariant& aVariant = theFieldStepData[ anIndex ];
2797 if( aVariant.type() == QVariant::String )
2798 aStringList << aVariant.toString();
2803 if( aVariant.type() == QVariant::Bool )
2805 aValue = aVariant.toBool() ? 1.0 : 0.0;
2811 if( aVariant.type() == QVariant::LongLong )
2812 aValue = double( aVariant.toLongLong() );
2813 else if( aVariant.type() == QVariant::Double )
2814 aValue = aVariant.toDouble();
2815 aNorm += aValue * aValue;
2821 aGroupedList << aStringList.join( "\n" );
2825 aNorm /= theFieldNbComponents;
2827 aNorm = pow( aNorm, 0.5 );
2829 if( aGroupedList.isEmpty() )
2830 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2833 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2834 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2837 aGroupedList << aNorm;
2843 theFieldStepRangeMin = 0.0;
2844 theFieldStepRangeMax = 1.0;
2847 SUIT_Session* session = SUIT_Session::session();
2848 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2849 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2851 QListIterator<QVariant> anIter( aGroupedList );
2852 while( anIter.hasNext() )
2854 const QVariant& aVariant = anIter.next();
2856 aResultList << aVariant;
2860 Quantity_Color aColor;
2861 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2862 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2863 aResultList << aQColor;
2869 // Note: the method is copied from Aspect_ColorScale class
2870 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2871 const Standard_Integer aMin,
2872 const Standard_Integer aMax )
2874 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2876 Standard_Integer aHue = maxLimit;
2878 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2880 aHue = Min( Max( minLimit, aHue ), maxLimit );
2885 // Note: the method is copied from Aspect_ColorScale class
2886 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2887 const Standard_Real aMin,
2888 const Standard_Real aMax,
2889 const Standard_Integer ColorsCount,
2890 Quantity_Color& aColor )
2892 if( aValue<aMin || aValue>aMax || aMax<aMin )
2893 return Standard_False;
2897 Standard_Real IntervNumber = 0;
2900 else if( aValue>aMax )
2901 IntervNumber = ColorsCount-1;
2902 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2903 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2905 Standard_Integer Interv = Standard_Integer( IntervNumber );
2907 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2909 return Standard_True;
2913 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2915 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2919 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2923 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2924 if( aViewer.IsNull() )
2927 aViewer->InitActiveViews();
2928 if( !aViewer->MoreActiveViews() )
2931 Handle(V3d_View) aView = aViewer->ActiveView();
2932 if( aView.IsNull() )
2935 Standard_Boolean anIsDisplayColorScale = Standard_False;
2936 TCollection_AsciiString aColorScaleTitle;
2937 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2938 Standard_Boolean anIsBoolean = Standard_False;
2940 SALOME_ListIO aSelectedObjects;
2941 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2942 if( aSelectedObjects.Extent() == 1 )
2944 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2945 if( !anIO.IsNull() )
2947 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2950 AIS_ListOfInteractive aList;
2951 aPrs->GetObjects( aList );
2952 AIS_ListIteratorOfListOfInteractive anIter( aList );
2953 for( ; anIter.More(); anIter.Next() )
2955 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2956 if( !aShape.IsNull() )
2958 GEOM::field_data_type aFieldDataType;
2959 int aFieldDimension;
2960 QList<QVariant> aFieldStepData;
2961 TCollection_AsciiString aFieldStepName;
2962 double aFieldStepRangeMin, aFieldStepRangeMax;
2963 aShape->getFieldStepInfo( aFieldDataType,
2968 aFieldStepRangeMax );
2969 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2971 anIsDisplayColorScale = Standard_True;
2972 aColorScaleTitle = aFieldStepName;
2973 aColorScaleMin = aFieldStepRangeMin;
2974 aColorScaleMax = aFieldStepRangeMax;
2975 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2983 if( anIsDisplayColorScale )
2985 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2986 if( !aColorScale.IsNull() )
2988 SUIT_Session* session = SUIT_Session::session();
2989 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2991 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2992 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2993 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2994 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2995 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2996 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2998 aColorScale->SetXPosition( anXPos );
2999 aColorScale->SetYPosition( anYPos );
3000 aColorScale->SetWidth( aWidth );
3001 aColorScale->SetHeight( aHeight );
3003 aColorScale->SetTextHeight( aTextHeight );
3004 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3006 aColorScale->SetTitle( aColorScaleTitle );
3007 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3009 if( !aView->ColorScaleIsDisplayed() )
3010 aView->ColorScaleDisplay();
3014 if( aView->ColorScaleIsDisplayed() )
3015 aView->ColorScaleErase();
3018 if( theIsRedisplayFieldSteps )
3020 _PTR(Study) aStudyDS = aStudy->studyDS();
3021 QList<SUIT_ViewManager*> vmList;
3022 myApp->viewManagers( vmList );
3023 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3025 if( SUIT_ViewManager* aViewManager = *vmIt )
3027 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3028 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3030 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3033 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3034 if( !CORBA::is_nil( anObject ) )
3036 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3037 if( !aFieldStep->_is_nil() )
3039 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3040 Handle(SALOME_InteractiveObject) aStepIO =
3041 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3042 Redisplay( aStepIO, false, false );