+void GEOM_Displayer::SetName( const char* theName )
+{
+ myName = theName;
+}
+
+void GEOM_Displayer::UnsetName()
+{
+ myName = "";
+}
+
+SalomeApp_Study* GEOM_Displayer::getStudy() const
+{
+ return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
+}
+
+void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
+{
+ myIO = theIO;
+}
+
+void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
+{
+ myShape = theShape;
+}
+
+bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
+{
+ _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
+ GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects only
+ return !CORBA::is_nil( aGeomObj ) && (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
+}
+
+int GEOM_Displayer::SetDisplayMode( const int theMode )
+{
+ int aPrevMode = myDisplayMode;
+ if ( theMode != -1 ) {
+ myDisplayMode = theMode;
+ myHasDisplayMode = true;
+ }
+ else {
+ UnsetDisplayMode();
+ }
+ return aPrevMode;
+}
+
+int GEOM_Displayer::GetDisplayMode() const
+{
+ return myDisplayMode;
+}
+
+int GEOM_Displayer::UnsetDisplayMode()
+{
+ int aPrevMode = myDisplayMode;
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
+ myHasDisplayMode = false;
+ return aPrevMode;
+}
+
+bool GEOM_Displayer::HasDisplayMode() const
+{
+ return myHasDisplayMode;
+}
+
+SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
+{
+ static QList<QColor> colors;
+
+ if ( colors.isEmpty() ) {
+
+ for (int s = 0; s < 2 ; s++)
+ {
+ for (int v = 100; v >= 40; v = v - 20)
+ {
+ for (int h = 0; h < 359 ; h = h + 60)
+ {
+ colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
+ }
+ }
+ }
+ }
+
+ static int currentColor = 0;
+
+ SALOMEDS::Color color;
+ color.R = (double)colors[currentColor].red() / 255.0;
+ color.G = (double)colors[currentColor].green() / 255.0;
+ color.B = (double)colors[currentColor].blue() / 255.0;
+
+ currentColor = (currentColor+1) % colors.count();
+
+ return color;
+}
+
+SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
+{
+ int aHue = -1;
+ int aTolerance = 64;
+ int anIterations = 0;
+ int aPeriod = 5;
+
+ while( 1 )
+ {
+ anIterations++;
+ if( anIterations % aPeriod == 0 )
+ {
+ aTolerance /= 2;
+ if( aTolerance < 1 )
+ break;
+ }
+ //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
+
+ aHue = (int)( 360.0 * rand() / RAND_MAX );
+ //std::cout << "Hue = " << aHue << std::endl;
+
+ //std::cout << "Auto colors : ";
+ bool ok = true;
+ QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
+ QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
+ for( ; it != itEnd; ++it )
+ {
+ SALOMEDS::Color anAutoColor = *it;
+ QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
+
+ int h, s, v;
+ aQColor.getHsv( &h, &s, &v );
+ //std::cout << h << " ";
+ if( abs( h - aHue ) < aTolerance )
+ {
+ ok = false;
+ //std::cout << "break (diff = " << abs( h - aHue ) << ")";
+ break;
+ }
+ }
+ //std::cout << std::endl;
+
+ if( ok )
+ break;
+ }
+
+ //std::cout << "Hue of the returned color = " << aHue << std::endl;
+ QColor aColor;
+ aColor.setHsv( aHue, 255, 255 );
+
+ SALOMEDS::Color aSColor;
+ aSColor.R = (double)aColor.red() / 255.0;
+ aSColor.G = (double)aColor.green() / 255.0;
+ aSColor.B = (double)aColor.blue() / 255.0;
+
+ return aSColor;
+}
+
+PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
+ const QString& entry,
+ SALOME_View* view )
+{
+ // get default properties for the explicitly specified default view type
+ PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
+
+ if ( study && view ) {
+ SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
+ SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
+ int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
+
+ if ( viewModel && viewId != -1 ) {
+ // get properties from the study
+ PropMap storedMap = study->getObjectPropMap( viewId, entry );
+ // overwrite default properties from stored ones (that are specified)
+ for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
+ if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
+ propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
+ storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
+ }
+ // ... specific processing for color
+ // ... current implementation is to use same stored color for all aspects
+ // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
+ if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
+ propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
+ propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
+ propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
+ propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
+ propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
+ }
+
+ if ( !entry.isEmpty() ) {
+ // get CORBA reference to geom object
+ _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
+ if ( SO ) {
+ CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
+ if ( !CORBA::is_nil( object ) ) {
+ GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
+ // check that geom object has color properly set
+ bool hasColor = false;
+ SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
+ // set color from geometry object (only once, if it is not yet set in GUI)
+ // current implementation is to use same color for all aspects
+ // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
+ if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
+ QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
+ propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
+ propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
+ propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
+ propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
+ propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
+ }
+ // check that object has point marker properly set
+ GEOM::marker_type mType = geomObject->GetMarkerType();
+ GEOM::marker_size mSize = geomObject->GetMarkerSize();
+ int mTextureId = geomObject->GetMarkerTexture();
+ bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
+ ( mType == GEOM::MT_USER && mTextureId > 0 );
+ // set point marker from geometry object (only once, if it is not yet set in GUI)
+ if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
+ if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
+ // standard type
+ propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
+ QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
+ }
+ else if ( mType == GEOM::MT_USER ) {
+ // custom texture
+ propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return propMap;
+}
+
+PropMap GEOM_Displayer::getDefaultPropertyMap()
+{
+ PropMap propMap;
+
+ // get resource manager
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+
+ // fill in the properties map with default values
+
+ // - visibility (false by default)
+ propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
+
+ // - nb isos (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
+ QString( "%1%2%3" ).
+ arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
+ arg( GEOM::subSectionSeparator() ).
+ arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
+
+ // - transparency (opacity = 1-transparency)
+ propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
+
+ // - display mode (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
+ resMgr->integerValue( "Geometry", "display_mode", 0 ) );
+
+ // - show edges direction flag (false by default)
+ propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
+
+ // - shading color (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
+ colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
+
+ // - wireframe color (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
+ colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
+
+ // - standalone edges color (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::LineColor ),
+ colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
+
+ // - free boundaries color (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
+ colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
+
+ // - points color (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::PointColor ),
+ colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
+
+ // - isos color (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
+ colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
+
+ // - outlines color (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
+ colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
+
+ // - deflection coefficient (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::Deflection ),
+ resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
+
+ // - material (take default value from preferences)
+ Material_Model material;
+ material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
+ propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
+
+ // - edge width (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
+ resMgr->integerValue( "Geometry", "edge_width", 1 ) );
+
+ // - isos width (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
+ resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
+
+ // - point marker (take default value from preferences)
+ propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
+ QString( "%1%2%3" ).
+ arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
+ arg( GEOM::subSectionSeparator() ).
+ arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
+
+ // - top-level flag (false by default)
+ propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
+
+ return propMap;
+}
+
+SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
+ SALOMEDS::Color aSColor;
+ hasColor = false;
+
+ SUIT_Session* session = SUIT_Session::session();
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
+
+ if ( app && !theGeomObject->_is_nil()) {
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+
+ if ( study ) {
+ _PTR(Study) aStudy = study->studyDS();
+ aSColor = theGeomObject->GetColor();
+ hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
+ if ( !hasColor ) {
+#ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
+ bool general_autocolor = true;
+#else // auto-color for groups only
+ bool general_autocolor = false;
+#endif // GENERAL_AUTOCOLOR
+ if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
+ GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
+ if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
+#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
+ aSColor = getPredefinedUniqueColor();
+ hasColor = true;
+#else // old algorithm for auto-colors
+ QList<SALOMEDS::Color> aReservedColors;
+ CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
+ _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
+ if ( aMainSObject ) {
+ _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
+ for ( ; it->More(); it->Next() ) {
+ _PTR(SObject) aChildSObject( it->Value() );
+ GEOM::GEOM_Object_var aChildObject =
+ GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
+ if ( CORBA::is_nil( aChildObject ) )
+ continue;
+
+ SALOMEDS::Color aReservedColor = aChildObject->GetColor();
+ if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
+ aReservedColors.append( aReservedColor );
+ }
+ }
+ aSColor = getUniqueColor( aReservedColors );
+ hasColor = true;
+#endif // SIMPLE_AUTOCOLOR
+ }
+ }
+ }
+ }
+ }
+ return aSColor;
+}
+
+
+void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
+ const bool eraseOnlyChildren) {
+ SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+ if ( !app )
+ return;
+
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+ if ( !appStudy )
+ return;
+
+ LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
+
+ if( !parent)
+ return;
+
+ // Erase from all views
+ QList<SALOME_View*> views;
+ SALOME_View* view;
+ ViewManagerList vmans = app->viewManagers();
+ SUIT_ViewManager* vman;
+ foreach ( vman, vmans ) {
+ SUIT_ViewModel* vmod = vman->getViewModel();
+ view = dynamic_cast<SALOME_View*> ( vmod );
+ if ( view )
+ views.append( view );
+ }
+
+ if( views.count() == 0 )
+ return;
+
+ //Erase childrens w/o update views
+ DataObjectList listObj = parent->children( true );
+ SUIT_DataObject* obj;
+ foreach( obj, listObj ) {
+ LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
+ if(l_obj)
+ foreach ( view, views ) {
+ Handle(SALOME_InteractiveObject) anIO =
+ new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
+ Erase(anIO, false, false, view);
+ }
+ }
+
+ //Erase parent with view update or repaint views
+ foreach ( view, views ) {
+ if(!eraseOnlyChildren)
+ Erase(theIO, false, true, view);
+ else
+ view->Repaint();
+ }
+}