+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
+{
+ return 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;
+ else
+ {
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
+ }
+ 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 );
+ return aPrevMode;
+}
+
+SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
+{
+ static QList<QColor> colors;
+
+ if ( colors.isEmpty() ) {
+ const int rfactor = 4; // red color component split factor, must be > 0
+ const int gfactor = 4; // green color component split factor, must be > 0
+ const int bfactor = 3; // blue color component split factor, must be > 0
+ // -
+ // total number of pre-defined colors is defined as
+ // nbcolors = rfactor * gfactor * bfactor
+ // NB: all three factors should not have same values
+ // otherwise all colors will be greyish
+
+ for ( int g = 0; g < gfactor; g++ ) {
+ for ( int r = 0; r < rfactor; r++ ) {
+ for ( int b = 0; b < bfactor; b++ )
+ colors.append( QColor( qRgb( r * 255 / (rfactor-1), g * 255 / (gfactor-1), b * 255 / (bfactor-1) ) ) );
+ }
+ }
+ }
+
+ 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::getDefaultPropertyMap(const QString& viewer_type) {
+ PropMap aDefaultMap;
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ //1. Visibility
+ aDefaultMap.insert(VISIBILITY_PROP , 1);
+
+ //2. Nb Isos
+ int anUIsoNumber;
+ int aVIsoNumber;
+ if(viewer_type == SOCC_Viewer::Type()) {
+ anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
+ aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
+ } else if( viewer_type==SVTK_Viewer::Type()) {
+ anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
+ aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1);
+ }
+ QString anIsos("%1%2%3");
+ anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber);
+ aDefaultMap.insert(ISOS_PROP , anIsos);
+
+ //3. Transparency
+ aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 );
+
+ //4. Display Mode
+ aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0));
+
+ //5. Vector Mode
+ aDefaultMap.insert( VECTOR_MODE_PROP , 0);
+
+ //6. Color
+ QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
+ aDefaultMap.insert( COLOR_PROP , col);
+
+ //7. Deflection Coeff
+ double aDC;
+
+ if(viewer_type == SOCC_Viewer::Type()) {
+ aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
+ } else if( viewer_type==SVTK_Viewer::Type()) {
+ aDC = 0.001;
+ }
+
+ aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
+
+ //8. Material
+ Material_Model material;
+ QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
+ material.fromResources( mname );
+ aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );
+
+ //9. Width of the edges
+ aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
+
+
+ //10. Width of iso-lines
+ aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
+
+ if(viewer_type == SOCC_Viewer::Type()) {
+
+ aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
+ }
+
+ return aDefaultMap;
+}
+
+bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) {
+ int nbInserted = 0;
+ if(!theOrigin.contains(VISIBILITY_PROP)) {
+ theOrigin.insert(VISIBILITY_PROP, 0);
+ nbInserted++;
+ }
+ if(!theOrigin.contains(TRANSPARENCY_PROP)) {
+ theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP));
+ nbInserted++;
+ }
+ if(!theOrigin.contains(DISPLAY_MODE_PROP)) {
+ theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP));
+ nbInserted++;
+ }
+ if(!theOrigin.contains(ISOS_PROP)) {
+ theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP));
+ nbInserted++;
+ }
+ if(!theOrigin.contains(VECTOR_MODE_PROP)) {
+ theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP));
+ nbInserted++;
+ }
+ if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) {
+ theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
+ nbInserted++;
+ }
+ if(!theOrigin.contains(MATERIAL_PROP)) {
+ theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
+ nbInserted++;
+ }
+
+ if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
+ theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
+ nbInserted++;
+ }
+
+ if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
+ theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
+ nbInserted++;
+ }
+
+ if(!theOrigin.contains(COLOR_PROP)) {
+ theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
+ nbInserted++;
+ }
+
+ return (nbInserted > 0);
+}
+
+
+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();
+ }
+}