1 // Copyright (C) 2007-2015 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>
67 #include "utilities.h"
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
71 #include "utilities.h"
74 #include <SOCC_ViewModel.h>
77 #include <SVTK_ViewModel.h>
79 #include <OCCViewer_ViewWindow.h>
80 #include <OCCViewer_ViewPort3d.h>
81 #include <OCCViewer_Utilities.h>
84 #include <AIS_Drawer.hxx>
85 #include <AIS_Dimension.hxx>
86 #include <AIS_LengthDimension.hxx>
87 #include <AIS_DiameterDimension.hxx>
88 #include <AIS_AngleDimension.hxx>
89 #include <AIS_ListIteratorOfListOfInteractive.hxx>
90 #include <Aspect_PolygonOffsetMode.hxx>
91 #include <Aspect_ColorScale.hxx>
92 #include <Prs3d_IsoAspect.hxx>
93 #include <Prs3d_PointAspect.hxx>
94 #include <StdSelect_TypeOfEdge.hxx>
95 #include <StdSelect_TypeOfFace.hxx>
96 #include <StdSelect_DisplayMode.hxx>
97 #include <TopoDS_Face.hxx>
98 #include <BRep_Tool.hxx>
99 #include <Geom_Plane.hxx>
100 #include <Geom_Axis2Placement.hxx>
101 #include <Graphic3d_AspectFillArea3d.hxx>
102 #include <gp_Pln.hxx>
103 #include <TColStd_MapOfInteger.hxx>
104 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
105 #include <TopoDS_Iterator.hxx>
106 #include <Graphic3d_AspectMarker3d.hxx>
107 #include <TopTools_MapOfShape.hxx>
108 #include <TopTools_ListOfShape.hxx>
109 #include <TopTools_ListIteratorOfListOfShape.hxx>
110 #include <TopoDS.hxx>
111 #include <NCollection_DataMap.hxx>
112 #include <NCollection_Map.hxx>
114 #include <Prs3d_ShadingAspect.hxx>
116 #include <BRepMesh_IncrementalMesh.hxx>
119 #include <vtkActorCollection.h>
120 #include <vtkProperty.h>
123 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
125 #include <GEOMImpl_Types.hxx>
127 #include <TColStd_HArray1OfByte.hxx>
129 // If the next macro is defined, autocolor feature works for all sub-shapes;
130 // if it is undefined, autocolor feature works for groups only
131 #define GENERAL_AUTOCOLOR
132 // Below macro, when uncommented, switches on simplified (more performant) algorithm
133 // of auto-color picking up
134 #define SIMPLE_AUTOCOLOR
136 // Hard-coded value of shape deflection coefficient for VTK viewer
137 const double VTK_MIN_DEFLECTION = 0.001;
138 // If the next macro is defined, the deflection coefficient for VTK presentation
139 // is limited by VTK_MIN_DEFLECTION
140 //#define LIMIT_DEFLECTION_FOR_VTK
142 // Pixmap caching support
145 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
146 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
147 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
149 static inline PixmapUsageMap& getPixmapUsageMap()
151 static PixmapUsageMap aMap;
155 static inline PixmapCacheMap& getPixmapCacheMap()
157 static PixmapCacheMap aMap;
161 //===========================================================================
162 // Function : getDefaultTexture
163 // Purpose : Get default texture
164 //===========================================================================
165 static inline Handle(Image_PixMap) getDefaultTexture()
167 static Handle(Image_PixMap) aPixmap;
168 if ( aPixmap.IsNull() ) {
169 QPixmap px(":images/default_texture.png");
171 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
176 //===========================================================================
177 // Function : cacheTextureFor
178 // Purpose : Load and cache image for the specified presentation.
179 //===========================================================================
180 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
181 const Handle(GEOM_AISShape)& theShape )
183 if ( thePath.isEmpty() )
186 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
187 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
189 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
190 if ( !aPixmap.IsNull() ) {
191 // point that the texture is used by the presentation
192 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
193 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
195 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
200 // convert texture to compatible image format
201 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
202 if ( anImage.isNull() )
205 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
207 aPixmapCacheMap.insert( thePath, aPixmap );
209 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
210 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
212 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
217 //===========================================================================
218 // Function : releaseTextures
219 // Purpose : Releases cached textures found for the specified presentation.
220 //===========================================================================
221 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
223 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
225 AIS_ListOfInteractive aListOfIO;
227 anOccPrs->GetObjects( aListOfIO );
229 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
231 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
232 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
234 for ( ; aIterateIO.More(); aIterateIO.Next() )
236 Handle(GEOM_AISShape) aAISShape =
237 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
239 if ( aAISShape.IsNull() )
242 #ifdef USE_TEXTURED_SHAPE
243 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
244 if ( aPixmap.IsNull() )
247 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
250 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
252 aUsersShapes.Remove( aAISShape );
254 if ( aUsersShapes.IsEmpty() ) {
255 aPixmapUsersMap.UnBind( aPixmap );
256 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
262 uint randomize( uint size )
264 static bool initialized = false;
265 if ( !initialized ) {
266 qsrand( QDateTime::currentDateTime().toTime_t() );
270 v = uint( (double)( v ) / RAND_MAX * size );
271 v = qMax( uint(0), qMin ( v, size-1 ) );
276 //================================================================
277 // Function : getActiveStudy
278 // Purpose : Get active study, returns 0 if no open study frame
279 //================================================================
280 static inline SalomeApp_Study* getActiveStudy()
282 SUIT_Session* session = SUIT_Session::session();
283 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
285 return ( SalomeApp_Study* )app->activeStudy();
289 static inline int getViewManagerId( SALOME_View* theViewFrame) {
290 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
291 SUIT_ViewManager* aViewMgr = 0;
293 aViewMgr = aModel->getViewManager();
294 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
297 //================================================================
298 // Function : getTopAbsMode
299 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
300 // one from GEOMImpl_Types.h
301 //================================================================
302 static inline int getTopAbsMode( const int implType )
306 case GEOM_COMPOUND : return TopAbs_COMPOUND;
307 case GEOM_SOLID : return TopAbs_SOLID;
308 case GEOM_SHELL : return TopAbs_SHELL;
309 case GEOM_FACE : return TopAbs_FACE;
310 case GEOM_WIRE : return TopAbs_WIRE;
311 case GEOM_EDGE : return TopAbs_EDGE;
312 case GEOM_POINT : return TopAbs_VERTEX;
317 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
319 if ( shape.IsNull() )
322 int ret = shape.ShapeType();
324 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
325 TopoDS_Iterator it(shape, Standard_True, Standard_False);
326 for (; it.More(); it.Next()) {
327 TopoDS_Shape sub_shape = it.Value();
328 if ( sub_shape.IsNull() ) continue;
329 int stype = getMinMaxShapeType( sub_shape, ismin );
330 if ( stype == TopAbs_SHAPE ) continue;
331 if ( ismin && stype > ret )
333 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
341 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
343 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
346 //================================================================
347 // Function : getFilter
348 // Purpose : Get filter corresponding to the type of object
349 // from GEOMImpl_Types.h
350 //================================================================
351 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
353 SUIT_SelectionFilter* aFilter;
355 int aTopAbsMode = getTopAbsMode( theMode );
356 if ( aTopAbsMode != -1 )
357 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
361 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
362 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
364 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
365 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
366 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
367 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
368 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
369 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
371 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
373 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
374 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
376 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
382 //================================================================
383 // Function : getComplexFilter
384 // Purpose : Get compound filter corresponding to the type of
385 // object from GEOMImpl_Types.h
386 //================================================================
387 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
389 GEOM_CompoundFilter* aFilter;
391 if(aSubShapes != NULL ) {
392 aFilter = new GEOM_CompoundFilter(getStudy());
393 QList<int> aTopAbsTypes;
394 QList<int>::const_iterator it;
395 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
396 int topAbsMode = getTopAbsMode(*it);
397 if(topAbsMode != -1 )
398 aTopAbsTypes.append(topAbsMode);
400 aFilter->addSubTypes(aTopAbsTypes);
406 //================================================================
407 // Function : getEntry
409 //================================================================
410 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
412 SUIT_Session* session = SUIT_Session::session();
413 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
416 CORBA::String_var IOR = app->orb()->object_to_string( object );
417 if ( strcmp(IOR.in(), "") != 0 )
419 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
420 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
428 //================================================================
429 // Function : getName
431 //================================================================
432 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
434 SUIT_Session* session = SUIT_Session::session();
435 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
438 CORBA::String_var IOR = app->orb()->object_to_string( object );
439 if ( strcmp(IOR.in(), "") != 0 )
441 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
442 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
444 _PTR(GenericAttribute) anAttr;
446 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
448 _PTR(AttributeName) aNameAttr( anAttr );
449 return aNameAttr->Value();
457 //=================================================================
459 * GEOM_Displayer::GEOM_Displayer
462 //=================================================================
463 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
466 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
471 SUIT_Session* session = SUIT_Session::session();
472 SUIT_ResourceMgr* resMgr = session->resourceMgr();
474 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
475 myShadingColor = SalomeApp_Tools::color( col );
477 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
478 myHasDisplayMode = false;
480 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
482 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
483 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
484 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
486 // Next properties provide a way to customize displaying of presentations;
487 // for instance, this is useful for preview
497 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
500 // Activate parallel vizualisation only for testing purpose
501 // and if the corresponding env variable is set to 1
502 char* parallel_visu = getenv("PARALLEL_VISU");
503 if (parallel_visu && atoi(parallel_visu))
505 MESSAGE("Parallel visualisation on");
506 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
511 myFieldDataType = GEOM::FDT_Double;
512 myFieldDimension = 0;
513 myFieldStepRangeMin = 0;
514 myFieldStepRangeMax = 0;
517 //=================================================================
519 * GEOM_Displayer::~GEOM_Displayer
522 //=================================================================
523 GEOM_Displayer::~GEOM_Displayer()
527 //=================================================================
529 * GEOM_Displayer::Display
530 * Display interactive object in the current viewer
532 //=================================================================
533 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
534 const bool updateViewer,
535 SALOME_View* theViewFrame )
537 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
540 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
544 vf->BeforeDisplay( this, prs );
545 vf->Display( this, prs );
546 vf->AfterDisplay( this, prs );
551 delete prs; // delete presentation because displayer is its owner
556 //=================================================================
558 * GEOM_Displayer::Display
559 * This overloaded Display() method can be useful for operations
560 * not using dialog boxes.
562 //=================================================================
563 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
565 if ( theObj->_is_nil() )
568 std::string entry = getEntry( theObj );
570 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
575 //=================================================================
577 * GEOM_Displayer::Erase
578 * Erase interactive object in the current viewer
580 //=================================================================
581 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
583 const bool updateViewer,
584 SALOME_View* theViewFrame )
586 if ( theIO.IsNull() )
589 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
592 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
594 vf->BeforeErase( this, prs );
595 vf->Erase( this, prs, forced );
596 vf->AfterErase( this, prs );
599 delete prs; // delete presentation because displayer is its owner
604 //=================================================================
606 * GEOM_Displayer::Erase
607 * Erase geometry object in the current viewer
609 //=================================================================
610 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
612 const bool updateViewer,
613 SALOME_View* theViewFrame)
615 std::string entry = getEntry( theObj );
618 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
619 forced, updateViewer, theViewFrame);
623 //=================================================================
625 * GEOM_Displayer::Redisplay
626 * Redisplay (erase and then display again) interactive object
627 * in the current viewer
629 //=================================================================
630 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
631 const bool updateViewer,
632 const bool checkActiveViewer )
634 // Remove the object permanently (<forced> == true)
635 SUIT_Session* ses = SUIT_Session::session();
636 SUIT_Application* app = ses->activeApplication();
639 SUIT_Desktop* desk = app->desktop();
640 QList<SUIT_ViewWindow*> wnds = desk->windows();
641 SUIT_ViewWindow* wnd;
642 QListIterator<SUIT_ViewWindow*> it( wnds );
643 while ( it.hasNext() && (wnd = it.next()) )
645 SUIT_ViewManager* vman = wnd->getViewManager();
648 SUIT_ViewModel* vmodel = vman->getViewModel();
651 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
654 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
656 Redisplay( theIO, updateViewer, view );
665 //=================================================================
667 * GEOM_Displayer::Redisplay
668 * Redisplay (erase and then display again) interactive object
669 * in the specified view
671 //=================================================================
672 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
673 const bool theUpdateViewer,
674 SALOME_View* theViewFrame )
676 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
682 Erase( theIO, true, false, theViewFrame );
683 Display( theIO, theUpdateViewer, theViewFrame );
686 //=================================================================
688 * GEOM_Displayer::Display
689 * Calls Display() method for each object in the given list
691 //=================================================================
692 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
694 SALOME_ListIteratorOfListIO Iter( theIOList );
695 for ( ; Iter.More(); Iter.Next() ) {
696 Display( Iter.Value(), false );
702 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
704 SalomeApp_Study* aStudy = getStudy();
706 if ( v ) vId = getViewManagerId( v );
709 QString entry = p->GetEntry();
710 if ( !entry.isEmpty() ) {
712 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
713 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
718 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
723 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
725 // VSR: this method can be improved in future:
726 // to improve performance, the default values from resource manager should be cached in the displayer
727 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
730 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
732 // VSR: this method can be improved in future:
733 // to improve performance, the default values from resource manager should be cached in the displayer
734 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
737 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
739 // check that shape is not null
740 if ( AISShape.IsNull() ) return;
742 // check that study is active
743 SalomeApp_Study* study = getStudy();
744 if ( !study ) return;
746 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
747 !TopoDS_Iterator(myShape).More() )
748 return; // NPAL15983 (Bug when displaying empty groups)
750 // set interactive object
752 Handle( SALOME_InteractiveObject ) anIO;
754 if ( !myIO.IsNull() ) {
755 AISShape->setIO( myIO );
756 AISShape->SetOwner( myIO );
759 else if ( !myName.empty() ) {
760 // workaround to allow selection of temporary objects
761 static int tempId = 0;
762 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
763 AISShape->setIO( anIO );
764 AISShape->SetOwner( anIO );
767 // flag: only vertex or compound of vertices is processed (specific handling)
768 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
769 // presentation study entry (empty for temporary objects like preview)
770 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
771 // flag: temporary object
772 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
773 // currently active view window's ID (-1 if no active view)
774 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
776 // get presentation properties
777 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
779 // Temporary staff: vertex must be infinite for correct visualization
780 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
783 Material_Model material;
784 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
786 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
787 // - set front material properties
788 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
789 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
790 // - set back material properties
791 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
792 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
793 // - switch to default (both sides) facing mode
794 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
800 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
801 // we set it to the shape not taking into account material properties
802 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
804 else if ( !material.isPhysical() ) {
805 // shading color from properties is used only for non-physical materials
806 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
810 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
811 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
812 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
813 AISShape->Attributes()->SetLineAspect( anAspect );
815 // - unfree boundaries color
816 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
817 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
818 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
819 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
821 // - free boundaries color
822 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
823 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
824 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
825 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
827 // - standalone edges color
828 anAspect = AISShape->Attributes()->WireAspect();
829 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
830 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
831 AISShape->Attributes()->SetWireAspect( anAspect );
833 // - color for edges in shading+edges mode
834 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
837 AISShape->SetDisplayMode( HasDisplayMode() ?
838 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
840 // display mode from properties
841 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
843 // - face boundaries color
844 if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
845 AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
846 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
847 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
848 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
850 // set display vectors flag
851 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
853 // set display vertices flag
854 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
855 AISShape->SetDisplayVertices( isVerticesMode );
858 if( HasTransparency() ) {
859 AISShape->SetTransparency( GetTransparency() );
861 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
864 // set iso properties
865 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
866 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
867 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
868 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
869 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
870 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
872 if ( HasIsosColor() ) {
873 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
874 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
877 uIsoAspect->SetColor( isosColor );
878 vIsoAspect->SetColor( isosColor );
881 if ( HasIsosWidth() ) {
882 uIsoAspect->SetWidth( GetIsosWidth() );
883 vIsoAspect->SetWidth( GetIsosWidth() );
886 uIsoAspect->SetWidth( isosWidth );
887 vIsoAspect->SetWidth( isosWidth );
891 uIsoAspect->SetNumber( GetNbIsos() );
892 vIsoAspect->SetNumber( GetNbIsos() );
895 uIsoAspect->SetNumber( uIsos );
896 vIsoAspect->SetNumber( vIsos );
899 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
900 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
902 // set deflection coefficient
903 // ... to avoid to small values of the coefficient, its lower value is limited
904 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
908 if ( HasTexture() ) {
909 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
910 aImagePath = GetTexture().c_str();
911 if ( ! entry.isEmpty() ) {
912 // check that study is active
913 SalomeApp_Study* study = getActiveStudy();
915 // Store the texture in object properties for next displays
916 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
917 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
919 // Update propeties map
920 propMap = getObjectProperties( study, entry, myViewFrame );
925 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
928 #ifdef USE_TEXTURED_SHAPE
929 Handle(Image_PixMap) aPixmap;
930 if ( !aImagePath.isEmpty() )
931 aPixmap = cacheTextureFor( aImagePath, AISShape );
933 aPixmap = getDefaultTexture();
935 // apply image to shape
936 if ( !aPixmap.IsNull() ) {
937 AISShape->SetTexturePixMap( aPixmap );
938 AISShape->SetTextureMapOn();
939 AISShape->DisableTextureModulate();
942 AISShape->SetTextureMapOff();
947 AISShape->SetWidth( HasWidth() ?
948 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
950 // libe width from properties
951 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
953 // set top-level flag
954 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
956 // set point marker (for vertex / compound of vertices only)
957 if ( onlyVertex || isVerticesMode ) {
958 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
959 if ( aList.size() == 2 ) {
960 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
961 int aTypeOfMarker = aList[0].toInt();
962 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
963 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
964 anAspect->SetScale( aScaleOfMarker );
965 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
966 anAspect->SetColor( HasColor() ?
967 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
968 (Quantity_NameOfColor)GetColor() :
969 // color from properties
970 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
971 AISShape->Attributes()->SetPointAspect( anAspect );
973 else if ( aList.size() == 1 ) {
974 // custom marker string contains "IdOfTexture"
975 int textureId = aList[0].toInt();
976 Standard_Integer aWidth, aHeight;
977 Handle(TColStd_HArray1OfByte) aTexture =
978 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
979 if ( !aTexture.IsNull() ) {
980 Handle(Prs3d_PointAspect) aTextureAspect =
981 new Prs3d_PointAspect( HasColor() ?
982 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
983 (Quantity_NameOfColor)GetColor() :
984 // color from properties
985 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
988 AISShape->Attributes()->SetPointAspect( aTextureAspect );
993 // set field step data
994 AISShape->setFieldStepInfo( myFieldDataType,
999 myFieldStepRangeMax );
1001 if ( create && !isTemporary && aMgrId != -1 ) {
1002 // set properties to the study
1003 study->setObjectProperties( aMgrId, entry, propMap );
1006 // AISShape->SetName(???); ??? necessary to set name ???
1009 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1011 // check that actor is not null
1012 if ( !actor ) return;
1014 // check that study is active
1015 SalomeApp_Study* study = getStudy();
1016 if ( !study ) return;
1018 // set interactive object
1020 Handle( SALOME_InteractiveObject ) anIO;
1022 if ( !myIO.IsNull() ) {
1023 actor->setIO( myIO );
1026 else if ( !myName.empty() ) {
1027 // workaround to allow selection of temporary objects
1028 static int tempId = 0;
1029 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1030 actor->setIO( anIO );
1033 // presentation study entry (empty for temporary objects like preview)
1034 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1035 // flag: temporary object
1036 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1037 // currently active view window's ID (-1 if no active view)
1038 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1040 // get presentation properties
1041 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1044 /////////////////////////////////////////////////////////////////////////
1045 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1046 // due to performance problem
1047 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1048 /////////////////////////////////////////////////////////////////////////
1049 if ( !actor->getTopo().IsSame( myShape ) )
1050 #ifdef LIMIT_DEFLECTION_FOR_VTK
1051 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1053 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1057 Material_Model material;
1058 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1059 std::vector<vtkProperty*> mprops;
1060 mprops.push_back( material.getMaterialVTKProperty( true ) );
1061 mprops.push_back( material.getMaterialVTKProperty( false) );
1062 actor->SetMaterial( mprops );
1064 // set iso-lines properties
1066 // - set number of iso-lines
1067 int nbIsos[2]= { 1, 1 };
1068 if ( HasNbIsos() ) {
1069 nbIsos[0] = GetNbIsos();
1070 nbIsos[1] = GetNbIsos();
1073 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1074 nbIsos[0] = isos[0].toInt();
1075 nbIsos[1] = isos[1].toInt();
1077 actor->SetNbIsos( nbIsos );
1079 // - set iso-lines width
1080 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1082 // - set iso-lines color
1083 if ( HasIsosColor() )
1084 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1086 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1087 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1092 // - same color for all sub-actors
1093 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1094 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1097 // shading color (for non-physical materials)
1098 if ( !material.isPhysical() ) {
1099 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1100 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1101 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1104 // - standalone edge color
1105 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1106 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1108 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1109 // - shared edges color ???
1110 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1112 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1113 // - free edges color ???
1114 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1117 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1118 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1121 // - color for edges in shading+edges mode
1122 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1123 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1126 if( HasTransparency() ) {
1127 actor->SetOpacity( 1.0 - GetTransparency() );
1129 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1133 actor->SetWidth( HasWidth() ?
1134 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1136 // libe width from properties
1137 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1139 // set display vectors flag
1140 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1142 // set display vertices flag
1143 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1146 int displayMode = HasDisplayMode() ?
1147 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1149 // display mode from properties
1150 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1152 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1153 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1154 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1155 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1157 if ( displayMode == 2 )
1158 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1159 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1161 actor->setDisplayMode( displayMode );
1164 actor->PickableOn();
1166 actor->PickableOff();
1168 if ( create && !isTemporary && aMgrId != -1 ) {
1169 // set properties to the study
1170 study->setObjectProperties( aMgrId, entry, propMap );
1174 //=================================================================
1176 * GEOM_Displayer::updateDimensions
1177 * Creates or renews dimension presentation for the IO.
1179 //=================================================================
1180 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1181 SALOME_OCCPrs* thePrs,
1182 const gp_Ax3& theShapeLCS )
1184 SalomeApp_Study* aStudy = getStudy();
1190 if ( theIO.IsNull() )
1195 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1197 AIS_ListOfInteractive aListOfIO;
1199 anOccPrs->GetObjects( aListOfIO );
1201 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1203 // remove outdated presentations of dimensions
1204 for ( ; aIterateIO.More(); aIterateIO.Next() )
1206 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1207 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1212 aListOfIO.Remove( aIterateIO );
1214 if ( !aIterateIO.More() )
1220 // prepare dimension styling
1221 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1223 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1224 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1225 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1226 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1227 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1228 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1229 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1231 // restore dimension presentation from saved attribute or property data
1232 AIS_ListOfInteractive aRestoredDimensions;
1234 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1236 GEOM::propertyName( GEOM::Dimensions ),
1239 GEOMGUI_DimensionProperty aRecords;
1241 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1243 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1247 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1250 // create up-to-date dimension presentations
1251 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1253 if ( !aRecords.IsVisible( aPrsIt ) )
1258 // init dimension by type
1259 Handle(AIS_Dimension) aPrs;
1260 switch( aRecords.GetType( aPrsIt ) )
1262 case GEOMGUI_DimensionProperty::DimensionType_Length :
1264 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1265 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1270 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1272 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1273 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1278 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1280 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1281 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1287 aPrs->SetOwner( theIO );
1289 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1291 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1293 aStyle->SetCommonColor( aColor );
1294 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1295 aStyle->MakeText3d( Standard_True );
1296 aStyle->MakeTextShaded( Standard_True );
1297 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1298 aStyle->TextAspect()->SetHeight( aFontHeight );
1299 aStyle->ArrowAspect()->SetLength( anArrowLength );
1300 aStyle->LineAspect()->SetWidth( aLineWidth );
1301 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1302 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1303 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1304 aPrs->SetDimensionAspect( aStyle );
1305 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1306 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1307 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1309 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1311 // show degree symbol for dimension instead of label "deg"
1312 if ( aUnitsAngle == "deg" )
1314 aPrs->SetSpecialSymbol(0xB0);
1315 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1316 aStyle->MakeUnitsDisplayed(Standard_False);
1320 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1321 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1326 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1329 aListOfIO.Append( aPrs );
1332 // update presentation
1335 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1337 anOccPrs->AddObject( aIterateIO.Value() );
1341 //=================================================================
1343 * GEOM_Displayer::Erase
1344 * Calls Erase() method for each object in the given list
1346 //=================================================================
1347 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1349 const bool updateViewer )
1351 SALOME_ListIteratorOfListIO Iter( theIOList );
1352 for ( ; Iter.More(); Iter.Next() )
1353 Erase( Iter.Value(), forced, false );
1359 //=================================================================
1361 * GEOM_Displayer::Redisplay
1362 * Calls Redisplay() method for each object in the given list
1364 //=================================================================
1365 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1366 const bool updateViewer,
1367 const bool checkActiveViewer )
1369 SALOME_ListIteratorOfListIO Iter( theIOList );
1370 for ( ; Iter.More(); Iter.Next() )
1371 Redisplay( Iter.Value(), false, checkActiveViewer );
1377 //=================================================================
1379 * GEOM_Displayer::Redisplay
1380 * Calls Redisplay() method for each object in the given list
1382 //=================================================================
1383 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1384 const bool theUpdateViewer,
1385 SALOME_View* theViewFrame )
1387 SALOME_ListIteratorOfListIO anIter( theIOList );
1388 for ( ; anIter.More(); anIter.Next() )
1390 Redisplay( anIter.Value(), false, theViewFrame );
1393 if ( theUpdateViewer )
1399 //=================================================================
1401 * GEOM_Displayer::Update
1402 * Update OCC presentaion
1403 * [ Reimplemented from SALOME_Displayer ]
1405 //=================================================================
1406 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1408 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1409 SalomeApp_Study* study = getStudy();
1411 if ( !occPrs || myShape.IsNull() || !study )
1414 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1417 // specific processing for local coordinate system presentation
1420 TopoDS_Face aFace = TopoDS::Face( myShape );
1421 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1422 if ( !aPlane.IsNull() )
1424 gp_Ax3 aPos = aPlane->Pln().Position();
1425 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1427 Handle(GEOM_AISTrihedron) aTrh;
1429 if ( occPrs->IsNull() )
1431 // new presentation is being created
1432 aTrh = new GEOM_AISTrihedron( aPlc );
1433 occPrs->AddObject( aTrh );
1437 // presentation is being updated
1438 AIS_ListOfInteractive aList;
1439 occPrs->GetObjects( aList );
1440 AIS_ListIteratorOfListOfInteractive anIter( aList );
1441 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1442 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1446 if ( !aTrh.IsNull() ) {
1447 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1449 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1450 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1452 aTrh->SetWidth( GetWidth() );
1454 if ( !myIO.IsNull() )
1456 aTrh->setIO( myIO );
1457 aTrh->SetOwner( myIO );
1459 aTrh->SetComponent( aPlc );
1460 aTrh->SetToUpdate();
1462 occPrs->SetToActivate( ToActivate() );
1468 // processing for usual geometry presentation
1471 // if presentation is empty we try to create new one
1472 if ( occPrs->IsNull() )
1474 // create presentation (specific for vectors)
1475 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1476 : new GEOM_AISShape ( myShape, "" );
1478 if( myType == GEOM_FIELD_STEP )
1479 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1480 // update shape properties
1481 updateShapeProperties( AISShape, true );
1483 // add shape to the presentation
1484 occPrs->AddObject( AISShape );
1486 // In accordance with ToActivate() value object will be activated/deactivated
1487 // when it will be displayed
1488 occPrs->SetToActivate( ToActivate() );
1490 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1491 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1493 // create additional wireframe shape
1494 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1495 aWirePrs->SetWidth(AISShape->Width());
1496 if ( !myIO.IsNull() ) {
1497 aWirePrs->setIO( myIO );
1498 aWirePrs->SetOwner( myIO );
1501 // add shape to the presentation
1502 occPrs->AddObject( aWirePrs );
1505 // if presentation is found -> set again shape for it
1508 AIS_ListOfInteractive IOList;
1509 occPrs->GetObjects( IOList );
1510 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1511 for ( ; Iter.More(); Iter.Next() )
1513 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1514 if ( AISShape.IsNull() )
1517 // re-set shape (it might be changed)
1518 if ( AISShape->Shape() != myShape )
1519 AISShape->Set( myShape );
1521 // update shape properties
1522 updateShapeProperties( AISShape, false );
1525 AISShape->UpdateSelection();
1526 AISShape->SetToUpdate();
1530 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1534 //=================================================================
1536 * GEOM_Displayer::Update
1537 * Update VTK presentaion
1538 * [ Reimplemented from SALOME_Displayer ]
1540 //=================================================================
1541 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1543 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1544 SalomeApp_Study* study = getStudy();
1546 if ( !vtkPrs || myShape.IsNull() || !study )
1549 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1552 // specific processing for local coordinate system presentation
1555 TopoDS_Face aFace = TopoDS::Face( myShape );
1556 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1557 if ( !aPlane.IsNull() ) {
1558 gp_Ax3 aPos = aPlane->Pln().Position();
1559 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1561 GEOM_VTKTrihedron* aTrh = 0;
1563 if ( vtkPrs->IsNull() ) {
1564 // new presentation is being created
1565 aTrh = GEOM_VTKTrihedron::New();
1566 vtkPrs->AddObject( aTrh );
1569 // presentation is being updated
1570 vtkActorCollection* actors = vtkPrs->GetObjects();
1572 actors->InitTraversal();
1573 vtkActor* a = actors->GetNextActor();
1574 while ( a && !aTrh ) {
1575 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1576 a = actors->GetNextActor();
1582 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1584 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1585 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1587 #ifdef VTK_TRIHEDRON_WIDTH
1589 // VSR: currently isn't supported
1591 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1593 aTrh->SetWidth( GetWidth() );
1596 if ( !myIO.IsNull() )
1597 aTrh->setIO( myIO );
1599 aTrh->SetPlacement( aPlc );
1606 // processing for usual geometry presentation
1609 // if presentation is empty we try to create new one
1610 if ( vtkPrs->IsNull() )
1613 GEOM_Actor* actor = GEOM_Actor::New();
1614 // update actor properties
1615 updateActorProperties( actor, true );
1616 // add actor to the presentation
1617 vtkPrs->AddObject( actor );
1620 // presentation is being updated
1621 vtkActorCollection* actors = vtkPrs->GetObjects();
1623 actors->InitTraversal();
1624 vtkActor* a = actors->GetNextActor();
1626 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1628 // update actor properties
1629 updateActorProperties( actor, false );
1630 a = actors->GetNextActor();
1638 //=================================================================
1640 * GEOM_Displayer::BuildPrs
1641 * Build presentation accordint to the current viewer type
1643 //=================================================================
1644 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1646 if ( theObj->_is_nil() )
1649 myViewFrame = GetActiveView();
1650 if ( myViewFrame == 0 )
1653 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1658 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1659 myType = theObj->GetType();
1661 // Update presentation
1667 //=================================================================
1669 * GEOM_Displayer::BuildPrs
1670 * Build presentation accordint to the current viewer type
1672 //=================================================================
1673 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1675 myViewFrame = GetActiveView();
1676 if ( theShape.IsNull() || myViewFrame == 0 )
1679 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1684 setShape( theShape );
1692 //=================================================================
1694 * GEOM_Displayer::buildPresentation
1695 * Builds/finds object's presentation for the current viewer
1696 * Calls corresponding Update() method by means of double dispatch
1699 //=================================================================
1700 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1701 SALOME_View* theViewFrame )
1703 SALOME_Prs* prs = 0;
1706 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1710 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1713 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1714 theIO->setEntry( entry.toLatin1().constData() );
1715 if ( !theIO.IsNull() )
1717 // set interactive object
1719 // Find SOBject (because shape should be published previously)
1720 SUIT_Session* session = SUIT_Session::session();
1721 SUIT_Application* app = session->activeApplication();
1724 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1727 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1730 // get CORBA reference to data object
1731 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1732 if ( !CORBA::is_nil( object ) )
1734 // downcast to GEOM base object
1735 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1736 if ( !GeomBaseObject->_is_nil() )
1738 myType = GeomBaseObject->GetType();
1740 // downcast to GEOM object
1741 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1742 if ( myType == GEOM_FIELD_STEP )
1744 // get the GEOM object from the field's shape
1745 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1746 if ( !GeomFieldStep->_is_nil() )
1748 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1749 if ( !GeomField->_is_nil() )
1750 GeomObject = GeomField->GetShape();
1753 // read the field step information
1754 readFieldStepInfo( GeomFieldStep );
1757 if ( !GeomObject->_is_nil() )
1759 // finally set shape
1760 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1768 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1774 //=================================================================
1776 * GEOM_Displayer::buildSubshapePresentation
1777 * Builds/finds object's presentation for the current viewer
1778 * Calls corresponding Update() method by means of double dispatch
1779 * For not published objects (for Mantis issue 0020435)
1781 //=================================================================
1782 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1783 const QString& entry,
1784 SALOME_View* theViewFrame)
1786 SALOME_Prs* prs = 0;
1789 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1793 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1796 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1797 theIO->setEntry(entry.toLatin1().constData());
1798 if (!theIO.IsNull())
1800 // set interactive object
1802 // finally set shape
1804 myType = GEOM_SUBSHAPE;
1806 UpdatePrs(prs); // Update presentation by using of the double dispatch
1812 //=================================================================
1814 * GEOM_Displayer::internalReset
1815 * Resets internal data
1818 //=================================================================
1819 void GEOM_Displayer::internalReset()
1824 myFieldDataType = GEOM::FDT_Double;
1825 myFieldDimension = 0;
1826 myFieldStepData.clear();
1827 myFieldStepName.Clear();
1828 myFieldStepRangeMin = 0;
1829 myFieldStepRangeMax = 0;
1832 //=================================================================
1834 * GEOM_Displayer::LocalSelection
1835 * Activate selection of CAD shapes with activisation of selection
1836 * of their sub-shapes (with opened local context for OCC viewer)
1838 //=================================================================
1839 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1841 SUIT_Session* session = SUIT_Session::session();
1842 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1846 LightApp_SelectionMgr* sm = app->selectionMgr();
1848 // remove all filters from selection
1851 SALOME_View* vf = GetActiveView();
1853 if (!theIO.IsNull() && !vf->isVisible(theIO))
1855 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1856 vf->LocalSelection( prs, modes );
1857 delete prs; // delete presentation because displayer is its owner
1861 //=================================================================
1863 * GEOM_Displayer::LocalSelection
1864 * Activate selection of CAD shapes with activisation of selection
1865 * of their sub-shapes (with opened local context for OCC viewer)
1867 //=================================================================
1868 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1870 std::list<int> modes;
1871 modes.push_back( theMode );
1872 LocalSelection( theIO, modes );
1875 //=================================================================
1877 * GEOM_Displayer::globalSelection
1878 * Activate selection of CAD shapes without activisation of selection
1879 * of their sub-shapes (without opened local context for OCC viewer)
1881 //=================================================================
1882 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1884 TColStd_MapOfInteger aModes;
1885 aModes.Add( theMode );
1886 GlobalSelection( aModes, update );
1889 //=================================================================
1891 * GEOM_Displayer::globalSelection
1892 * Activate selection of CAD shapes without activisation of selection
1893 * of their sub-shapes (without opened local context for OCC viewer)
1895 //=================================================================
1896 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1897 const bool update, const QList<int>* theSubShapes )
1899 SUIT_Session* session = SUIT_Session::session();
1900 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1904 SALOME_View* vf = GetActiveView();
1908 // Close local context
1909 vf->GlobalSelection( update );
1911 // Set selection filters in accordance with current mode
1912 LightApp_SelectionMgr* sm = app->selectionMgr();
1916 // Remove from selection temporary objects if necessary
1917 if ( !theModes.Contains( GEOM_PREVIEW ) )
1918 clearTemporary( sm );
1920 //@ aSel->ClearIndex();
1924 // Remove filters from AIS_InteractiveContext
1925 Handle(AIS_InteractiveContext) ic;
1926 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1929 ic = viewer->getAISContext();
1931 ic->RemoveFilters();
1934 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1937 SUIT_SelectionFilter* aFilter;
1938 if ( theModes.Extent() == 1 )
1940 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1942 if ( aMode == GEOM_COMPOUNDFILTER )
1943 aFilter = getComplexFilter( theSubShapes );
1945 aFilter = getFilter( aMode );
1947 else if ( theModes.Extent() > 1 )
1949 TColStd_MapOfInteger aTopAbsModes;
1950 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1951 QList<SUIT_SelectionFilter*> aListOfFilters;
1952 for ( ; anIter.More(); anIter.Next() )
1954 SUIT_SelectionFilter* aFilter;
1955 int aMode = anIter.Key();
1956 if ( aMode == GEOM_COMPOUNDFILTER )
1957 aFilter = getComplexFilter( theSubShapes );
1959 aFilter = getFilter( aMode );
1962 aListOfFilters.append( aFilter );
1965 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1972 sm->installFilter( aFilter );
1975 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1976 ic->AddFilter( anOCCFilter );
1981 //=================================================================
1983 * GEOM_Displayer::LocalSelection
1984 * Activate selection of CAD shapes with activisation of selection
1985 * of their sub-shapes (with opened local context for OCC viewer)
1987 //=================================================================
1988 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
1990 SALOME_ListIteratorOfListIO Iter( theIOList );
1991 for ( ; Iter.More(); Iter.Next() )
1992 LocalSelection( Iter.Value(), modes );
1995 //=================================================================
1997 * GEOM_Displayer::LocalSelection
1998 * Activate selection of CAD shapes with activisation of selection
1999 * of their sub-shapes (with opened local context for OCC viewer)
2001 //=================================================================
2002 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2004 std::list<int> modes;
2005 modes.push_back( theMode );
2006 LocalSelection( theIOList, modes );
2009 //=================================================================
2011 * GEOM_Displayer::BeforeDisplay
2012 * Called before displaying of pars. Close local context
2013 * [ Reimplemented from SALOME_Displayer ]
2015 //=================================================================
2016 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2018 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2021 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2024 if ( ic->HasOpenedContext() )
2025 ic->CloseAllContexts();
2030 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2032 UpdateColorScale(false,false);
2035 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2037 LightApp_Displayer::BeforeErase( v, p );
2038 releaseTextures( p );
2041 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2043 LightApp_Displayer::AfterErase( v, p );
2044 UpdateColorScale(false,false);
2047 //=================================================================
2049 * GEOM_Displayer::SetColor
2050 * Set color for shape displaying. If it is equal -1 then default color is used.
2051 * Available values are from Quantity_NameOfColor enumeration
2053 //=================================================================
2054 void GEOM_Displayer::SetColor( const int color )
2061 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2065 int GEOM_Displayer::GetColor() const
2070 bool GEOM_Displayer::HasColor() const
2072 return myColor != -1;
2075 void GEOM_Displayer::UnsetColor()
2079 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2080 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2081 myShadingColor = SalomeApp_Tools::color( col );
2084 //=================================================================
2086 * GEOM_Displayer::SetTransparency
2087 * Set transparency for shape displaying.
2089 //=================================================================
2090 double GEOM_Displayer::SetTransparency( const double transparency )
2092 double prevTransparency = myTransparency;
2093 myTransparency = transparency;
2094 return prevTransparency;
2097 //=================================================================
2099 * GEOM_Displayer::GetTransparency
2100 * Get transparency for shape displaying.
2102 //=================================================================
2103 double GEOM_Displayer::GetTransparency() const
2105 return myTransparency;
2108 //=================================================================
2110 * GEOM_Displayer::HasTransparency
2111 * Check if transparency for shape displaying is set.
2113 //=================================================================
2114 bool GEOM_Displayer::HasTransparency() const
2116 return myTransparency >= 0;
2119 //=================================================================
2121 * GEOM_Displayer::UnsetTransparency
2122 * Unset transparency for shape displaying.
2124 //=================================================================
2125 double GEOM_Displayer::UnsetTransparency()
2127 return SetTransparency( -1 );
2130 //=================================================================
2132 * GEOM_Displayer::SetTexture
2134 //=================================================================
2135 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2137 myTexture = texureFileName;
2140 bool GEOM_Displayer::HasTexture() const
2142 return myTexture != "";
2145 std::string GEOM_Displayer::GetTexture() const
2150 //=================================================================
2152 * GEOM_Displayer::SetWidth
2153 * Set width of shape displaying. If it is equal -1 then default width is used.
2155 //=================================================================
2156 void GEOM_Displayer::SetWidth( const double width )
2161 double GEOM_Displayer::GetWidth() const
2166 bool GEOM_Displayer::HasWidth() const
2168 return myWidth != -1;
2171 void GEOM_Displayer::UnsetWidth()
2176 int GEOM_Displayer::GetIsosWidth() const
2181 void GEOM_Displayer::SetIsosWidth(const int width)
2183 myIsosWidth = width;
2186 bool GEOM_Displayer::HasIsosWidth() const
2188 return myIsosWidth != -1;
2191 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2193 int prevNbIsos = myNbIsos;
2198 int GEOM_Displayer::UnsetNbIsos()
2200 return SetNbIsos( -1 );
2203 int GEOM_Displayer::GetNbIsos() const
2208 bool GEOM_Displayer::HasNbIsos() const
2210 return myNbIsos >= 0;
2213 int GEOM_Displayer::SetIsosColor( const int color )
2215 int prevColor = myIsosColor;
2216 myIsosColor = color;
2220 int GEOM_Displayer::GetIsosColor() const
2225 bool GEOM_Displayer::HasIsosColor() const
2227 return myIsosColor != -1;
2230 int GEOM_Displayer::UnsetIsosColor()
2232 return SetIsosColor( -1 );
2235 //=================================================================
2237 * GEOM_Displayer::SetToActivate
2238 * This method is used for activisation/deactivisation of objects to be displayed
2240 //=================================================================
2241 void GEOM_Displayer::SetToActivate( const bool toActivate )
2243 myToActivate = toActivate;
2245 bool GEOM_Displayer::ToActivate() const
2247 return myToActivate;
2250 //=================================================================
2252 * GEOM_Displayer::clearTemporary
2253 * Removes from selection temporary objects
2255 //=================================================================
2256 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2258 SALOME_ListIO selected, toSelect;
2259 theSelMgr->selectedObjects( selected );
2261 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2262 Handle(SALOME_InteractiveObject) io = it.Value();
2263 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2264 toSelect.Append( it.Value() );
2267 theSelMgr->setSelectedObjects( toSelect, true );
2270 void GEOM_Displayer::SetName( const char* theName )
2275 void GEOM_Displayer::UnsetName()
2280 SalomeApp_Study* GEOM_Displayer::getStudy() const
2282 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2285 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2290 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2295 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2296 const int theFieldDimension,
2297 const QList<QVariant>& theFieldStepData,
2298 const TCollection_AsciiString& theFieldStepName,
2299 const double theFieldStepRangeMin,
2300 const double theFieldStepRangeMax )
2302 myFieldDataType = theFieldDataType;
2303 myFieldDimension = theFieldDimension;
2304 myFieldStepData = theFieldStepData;
2305 myFieldStepName = theFieldStepName;
2306 myFieldStepRangeMin = theFieldStepRangeMin;
2307 myFieldStepRangeMax = theFieldStepRangeMax;
2310 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2312 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2313 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2314 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2315 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2316 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2317 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2320 int GEOM_Displayer::SetDisplayMode( const int theMode )
2322 int aPrevMode = myDisplayMode;
2323 if ( theMode != -1 ) {
2324 myDisplayMode = theMode;
2325 myHasDisplayMode = true;
2333 int GEOM_Displayer::GetDisplayMode() const
2335 return myDisplayMode;
2338 int GEOM_Displayer::UnsetDisplayMode()
2340 int aPrevMode = myDisplayMode;
2341 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2342 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2343 myHasDisplayMode = false;
2347 bool GEOM_Displayer::HasDisplayMode() const
2349 return myHasDisplayMode;
2352 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2354 static QList<QColor> colors;
2356 if ( colors.isEmpty() ) {
2358 for (int s = 0; s < 2 ; s++)
2360 for (int v = 100; v >= 40; v = v - 20)
2362 for (int h = 0; h < 359 ; h = h + 60)
2364 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2370 static int currentColor = randomize( colors.size() );
2372 SALOMEDS::Color color;
2373 color.R = (double)colors[currentColor].red() / 255.0;
2374 color.G = (double)colors[currentColor].green() / 255.0;
2375 color.B = (double)colors[currentColor].blue() / 255.0;
2377 currentColor = (currentColor+1) % colors.count();
2382 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2385 int aTolerance = 64;
2386 int anIterations = 0;
2392 if( anIterations % aPeriod == 0 )
2395 if( aTolerance < 1 )
2398 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2400 aHue = (int)( 360.0 * rand() / RAND_MAX );
2401 //std::cout << "Hue = " << aHue << std::endl;
2403 //std::cout << "Auto colors : ";
2405 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2406 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2407 for( ; it != itEnd; ++it )
2409 SALOMEDS::Color anAutoColor = *it;
2410 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2413 aQColor.getHsv( &h, &s, &v );
2414 //std::cout << h << " ";
2415 if( abs( h - aHue ) < aTolerance )
2418 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2422 //std::cout << std::endl;
2428 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2430 aColor.setHsv( aHue, 255, 255 );
2432 SALOMEDS::Color aSColor;
2433 aSColor.R = (double)aColor.red() / 255.0;
2434 aSColor.G = (double)aColor.green() / 255.0;
2435 aSColor.B = (double)aColor.blue() / 255.0;
2440 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2441 const QString& entry,
2444 // get default properties for the explicitly specified default view type
2445 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2447 if ( study && view ) {
2448 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2449 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2450 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2452 if ( viewModel && viewId != -1 ) {
2453 // get properties from the study
2454 PropMap storedMap = study->getObjectProperties( viewId, entry );
2455 // overwrite default properties from stored ones (that are specified)
2456 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2457 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2458 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2459 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2461 // ... specific processing for color
2462 // ... current implementation is to use same stored color for all aspects
2463 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2464 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2465 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2466 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2467 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2468 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2469 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2472 if ( !entry.isEmpty() ) {
2473 // get CORBA reference to geom object
2474 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2476 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2477 if ( !CORBA::is_nil( object ) ) {
2478 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2479 if ( !CORBA::is_nil( geomObject ) ) { // to check
2480 // check that geom object has color properly set
2481 bool hasColor = false;
2482 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2483 // set color from geometry object (only once, if it is not yet set in GUI)
2484 // current implementation is to use same color for all aspects
2485 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2486 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2487 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2488 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2489 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2490 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2491 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2492 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2494 // check that object has point marker properly set
2495 GEOM::marker_type mType = geomObject->GetMarkerType();
2496 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2497 int mTextureId = geomObject->GetMarkerTexture();
2498 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2499 ( mType == GEOM::MT_USER && mTextureId > 0 );
2500 // set point marker from geometry object (only once, if it is not yet set in GUI)
2501 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2502 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2504 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2505 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2507 else if ( mType == GEOM::MT_USER ) {
2509 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2521 PropMap GEOM_Displayer::getDefaultPropertyMap()
2525 // get resource manager
2526 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2528 // fill in the properties map with default values
2530 // - visibility (false by default)
2531 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2533 // - nb isos (take default value from preferences)
2534 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2535 QString( "%1%2%3" ).
2536 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2537 arg( GEOM::subSectionSeparator() ).
2538 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2540 // - transparency (opacity = 1-transparency)
2541 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2542 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2544 // - display mode (take default value from preferences)
2545 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2546 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2548 // - show edges direction flag (false by default)
2549 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2551 // - show vertices flag (false by default)
2552 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2554 // - shading color (take default value from preferences)
2555 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2556 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2558 // - wireframe color (take default value from preferences)
2559 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2560 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2562 // - standalone edges color (take default value from preferences)
2563 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2564 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2566 // - free boundaries color (take default value from preferences)
2567 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2568 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2570 // - points color (take default value from preferences)
2571 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2572 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2574 // - isos color (take default value from preferences)
2575 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2576 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2578 // - outlines color (take default value from preferences)
2579 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2580 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2582 // - deflection coefficient (take default value from preferences)
2583 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2584 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2586 // - material (take default value from preferences)
2587 Material_Model material;
2588 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2589 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2591 // - edge width (take default value from preferences)
2592 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2593 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2595 // - isos width (take default value from preferences)
2596 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2597 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2599 // - point marker (take default value from preferences)
2600 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2601 QString( "%1%2%3" ).
2602 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2603 arg( GEOM::subSectionSeparator() ).
2604 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2606 // - top-level flag (false by default)
2607 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2612 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2613 SALOMEDS::Color aSColor;
2616 SUIT_Session* session = SUIT_Session::session();
2617 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2619 if ( app && !theGeomObject->_is_nil()) {
2620 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2623 _PTR(Study) aStudy = study->studyDS();
2624 aSColor = theGeomObject->GetColor();
2625 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2627 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2628 bool general_autocolor = true;
2629 #else // auto-color for groups only
2630 bool general_autocolor = false;
2631 #endif // GENERAL_AUTOCOLOR
2632 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2633 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2634 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2635 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2636 aSColor = getPredefinedUniqueColor();
2638 #else // old algorithm for auto-colors
2639 QList<SALOMEDS::Color> aReservedColors;
2640 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2641 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2642 if ( aMainSObject ) {
2643 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2644 for ( ; it->More(); it->Next() ) {
2645 _PTR(SObject) aChildSObject( it->Value() );
2646 GEOM::GEOM_Object_var aChildObject =
2647 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2648 if ( CORBA::is_nil( aChildObject ) )
2651 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2652 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2653 aReservedColors.append( aReservedColor );
2656 aSColor = getUniqueColor( aReservedColors );
2658 #endif // SIMPLE_AUTOCOLOR
2668 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2669 const bool eraseOnlyChildren) {
2670 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2674 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2678 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2683 // Erase from all views
2684 QList<SALOME_View*> views;
2686 ViewManagerList vmans = app->viewManagers();
2687 SUIT_ViewManager* vman;
2688 foreach ( vman, vmans ) {
2689 SUIT_ViewModel* vmod = vman->getViewModel();
2690 view = dynamic_cast<SALOME_View*> ( vmod );
2692 views.append( view );
2695 if( views.count() == 0 )
2698 //Erase childrens w/o update views
2699 DataObjectList listObj = parent->children( true );
2700 SUIT_DataObject* obj;
2701 foreach( obj, listObj ) {
2702 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2704 foreach ( view, views ) {
2705 Handle(SALOME_InteractiveObject) anIO =
2706 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2707 Erase(anIO, false, false, view);
2711 //Erase parent with view update or repaint views
2712 foreach ( view, views ) {
2713 if(!eraseOnlyChildren)
2714 Erase(theIO, false, true, view);
2720 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2722 if( theGeomFieldStep->_is_nil() )
2725 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2726 if( aGeomField->_is_nil() )
2729 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2730 if( aGeomFieldShape->_is_nil() )
2733 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2734 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2735 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2737 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2739 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2741 int aFieldDimension = aGeomField->GetDimension();
2743 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2744 int aFieldNbComponents = aFieldComponents->length();
2746 QList<QVariant> aFieldStepData;
2747 if( aFieldDataType == GEOM::FDT_Bool )
2749 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2750 if ( !aGeomBoolFieldStep->_is_nil() )
2752 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2753 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2754 aFieldStepData << (bool)aValues[i];
2757 else if( aFieldDataType == GEOM::FDT_Int )
2759 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2760 if ( !aGeomIntFieldStep->_is_nil() )
2762 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2763 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2764 aFieldStepData << (qlonglong)aValues[i];
2767 else if( aFieldDataType == GEOM::FDT_Double )
2769 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2770 if ( !aGeomDoubleFieldStep->_is_nil() )
2772 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2773 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2774 aFieldStepData << (double)aValues[i];
2777 else if( aFieldDataType == GEOM::FDT_String )
2779 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2780 if ( !aGeomStringFieldStep->_is_nil() )
2782 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2783 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2784 aFieldStepData << QString( aValues[i] );
2788 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2789 aFieldStepData = groupFieldData( aFieldStepData,
2791 aFieldDataType == GEOM::FDT_String,
2793 aFieldStepRangeMax );
2795 setFieldStepInfo( aFieldDataType,
2800 aFieldStepRangeMax );
2803 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2804 const int theFieldNbComponents,
2805 const bool theIsString,
2806 double& theFieldStepRangeMin,
2807 double& theFieldStepRangeMax )
2809 QList<QVariant> aResultList;
2810 theFieldStepRangeMin = 0;
2811 theFieldStepRangeMax = 0;
2813 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2816 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2818 QList<QVariant> aGroupedList;
2820 bool anIsBoolean = false;
2821 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2824 QStringList aStringList;
2826 int aBaseIndex = aSubShape * theFieldNbComponents;
2827 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2829 int anIndex = aComponent + aBaseIndex;
2831 const QVariant& aVariant = theFieldStepData[ anIndex ];
2834 if( aVariant.type() == QVariant::String )
2835 aStringList << aVariant.toString();
2840 if( aVariant.type() == QVariant::Bool )
2842 aValue = aVariant.toBool() ? 1.0 : 0.0;
2848 if( aVariant.type() == QVariant::LongLong )
2849 aValue = double( aVariant.toLongLong() );
2850 else if( aVariant.type() == QVariant::Double )
2851 aValue = aVariant.toDouble();
2852 aNorm += aValue * aValue;
2858 aGroupedList << aStringList.join( "\n" );
2862 aNorm /= theFieldNbComponents;
2864 aNorm = pow( aNorm, 0.5 );
2866 if( aGroupedList.isEmpty() )
2867 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2870 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2871 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2874 aGroupedList << aNorm;
2880 theFieldStepRangeMin = 0.0;
2881 theFieldStepRangeMax = 1.0;
2884 SUIT_Session* session = SUIT_Session::session();
2885 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2886 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2888 QListIterator<QVariant> anIter( aGroupedList );
2889 while( anIter.hasNext() )
2891 const QVariant& aVariant = anIter.next();
2893 aResultList << aVariant;
2897 Quantity_Color aColor;
2898 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2899 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2900 aResultList << aQColor;
2906 // Note: the method is copied from Aspect_ColorScale class
2907 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2908 const Standard_Integer aMin,
2909 const Standard_Integer aMax )
2911 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2913 Standard_Integer aHue = maxLimit;
2915 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2917 aHue = Min( Max( minLimit, aHue ), maxLimit );
2922 // Note: the method is copied from Aspect_ColorScale class
2923 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2924 const Standard_Real aMin,
2925 const Standard_Real aMax,
2926 const Standard_Integer ColorsCount,
2927 Quantity_Color& aColor )
2929 if( aValue<aMin || aValue>aMax || aMax<aMin )
2930 return Standard_False;
2934 Standard_Real IntervNumber = 0;
2937 else if( aValue>aMax )
2938 IntervNumber = ColorsCount-1;
2939 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2940 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2942 Standard_Integer Interv = Standard_Integer( IntervNumber );
2944 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2946 return Standard_True;
2950 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2952 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2956 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2960 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2961 if( aViewer.IsNull() )
2964 aViewer->InitActiveViews();
2965 if( !aViewer->MoreActiveViews() )
2968 Handle(V3d_View) aView = aViewer->ActiveView();
2969 if( aView.IsNull() )
2972 Standard_Boolean anIsDisplayColorScale = Standard_False;
2973 TCollection_AsciiString aColorScaleTitle;
2974 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2975 Standard_Boolean anIsBoolean = Standard_False;
2977 SALOME_ListIO aSelectedObjects;
2978 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2979 if( aSelectedObjects.Extent() == 1 )
2981 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2982 if( !anIO.IsNull() )
2984 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2987 AIS_ListOfInteractive aList;
2988 aPrs->GetObjects( aList );
2989 AIS_ListIteratorOfListOfInteractive anIter( aList );
2990 for( ; anIter.More(); anIter.Next() )
2992 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2993 if( !aShape.IsNull() )
2995 GEOM::field_data_type aFieldDataType;
2996 int aFieldDimension;
2997 QList<QVariant> aFieldStepData;
2998 TCollection_AsciiString aFieldStepName;
2999 double aFieldStepRangeMin, aFieldStepRangeMax;
3000 aShape->getFieldStepInfo( aFieldDataType,
3005 aFieldStepRangeMax );
3006 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3008 anIsDisplayColorScale = Standard_True;
3009 aColorScaleTitle = aFieldStepName;
3010 aColorScaleMin = aFieldStepRangeMin;
3011 aColorScaleMax = aFieldStepRangeMax;
3012 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3020 if( anIsDisplayColorScale )
3022 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
3023 if( !aColorScale.IsNull() )
3025 SUIT_Session* session = SUIT_Session::session();
3026 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3028 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3029 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3030 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3031 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3032 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3033 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3035 aColorScale->SetXPosition( anXPos );
3036 aColorScale->SetYPosition( anYPos );
3037 aColorScale->SetWidth( aWidth );
3038 aColorScale->SetHeight( aHeight );
3040 aColorScale->SetTextHeight( aTextHeight );
3041 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3043 aColorScale->SetTitle( aColorScaleTitle );
3044 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3046 if( !aView->ColorScaleIsDisplayed() )
3047 aView->ColorScaleDisplay();
3051 if( aView->ColorScaleIsDisplayed() )
3052 aView->ColorScaleErase();
3055 if( theIsRedisplayFieldSteps )
3057 _PTR(Study) aStudyDS = aStudy->studyDS();
3058 QList<SUIT_ViewManager*> vmList;
3059 myApp->viewManagers( vmList );
3060 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3062 if( SUIT_ViewManager* aViewManager = *vmIt )
3064 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3065 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3067 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3070 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3071 if( !CORBA::is_nil( anObject ) )
3073 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3074 if( !aFieldStep->_is_nil() )
3076 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3077 Handle(SALOME_InteractiveObject) aStepIO =
3078 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3079 Redisplay( aStepIO, false, false );