+//================================================================================
+/*!
+ * \brief Stops current operations and starts a given one
+ * \param id - The id of the operation to start
+ */
+//================================================================================
+
+void SMESHGUI::switchToOperation(int id)
+{
+ if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
+ activeStudy()->abortAllOperations();
+ startOperation( id );
+}
+
+LightApp_Displayer* SMESHGUI::displayer()
+{
+ if( !myDisplayer )
+ myDisplayer = new SMESHGUI_Displayer( getApp() );
+ return myDisplayer;
+}
+
+SALOMEDS::Color SMESHGUI::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;
+ }
+
+ aHue = (int)( 360.0 * rand() / RAND_MAX );
+
+ 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 );
+ if( abs( h - aHue ) < aTolerance )
+ {
+ ok = false;
+ break;
+ }
+ }
+
+ if( ok )
+ break;
+ }
+
+ QColor aColor;
+ aColor.setHsv( aHue, 255, 255 );
+
+ SALOMEDS::Color aSColor;
+ aSColor.R = aColor.redF();
+ aSColor.G = aColor.greenF();
+ aSColor.B = aColor.blueF();
+
+ return aSColor;
+}
+
+const char* gSeparator = "_"; // character used to separate parameter names
+const char* gDigitsSep = ":"; // character used to separate numeric parameter values (color = r:g:b)
+const char* gPathSep = "|"; // character used to separate paths
+
+/*!
+ * \brief Store visual parameters
+ *
+ * This method is called just before the study document is saved.
+ * Store visual parameters in AttributeParameter attribue(s)
+ */
+void SMESHGUI::storeVisualParameters (int savePoint)
+{
+ // localizing
+ Kernel_Utils::Localizer loc;
+
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
+ if (!appStudy || !appStudy->studyDS())
+ return;
+ _PTR(Study) studyDS = appStudy->studyDS();
+
+ // componentName is used for encoding of entries when storing them in IParameters
+ std::string componentName = myComponentSMESH->ComponentDataType();
+ //_PTR(SComponent) aSComponent = studyDS->FindComponent("SMESH");
+ //if (!aSComponent) return;
+
+ // IParameters
+ _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
+ componentName.c_str(),
+ savePoint);
+ _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
+
+ // store map of custom markers
+ const VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
+ if( !aMarkerMap.empty() )
+ {
+ VTK::MarkerMap::const_iterator anIter = aMarkerMap.begin();
+ for( ; anIter != aMarkerMap.end(); anIter++ )
+ {
+ int anId = anIter->first;
+ VTK::MarkerData aMarkerData = anIter->second;
+ std::string aMarkerFileName = aMarkerData.first;
+ VTK::MarkerTexture aMarkerTexture = aMarkerData.second;
+ if( aMarkerTexture.size() < 3 )
+ continue; // should contain at least width, height and the first value
+
+ QString aPropertyName( "texture" );
+ aPropertyName += gSeparator;
+ aPropertyName += QString::number( anId );
+
+ QString aPropertyValue = aMarkerFileName.c_str();
+ aPropertyValue += gPathSep;
+
+ VTK::MarkerTexture::const_iterator aTextureIter = aMarkerTexture.begin();
+ ushort aWidth = *aTextureIter++;
+ ushort aHeight = *aTextureIter++;
+ aPropertyValue += QString::number( aWidth ); aPropertyValue += gDigitsSep;
+ aPropertyValue += QString::number( aHeight ); aPropertyValue += gDigitsSep;
+ for( ; aTextureIter != aMarkerTexture.end(); aTextureIter++ )
+ aPropertyValue += QString::number( *aTextureIter );
+
+ ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
+ }
+ }
+
+ // viewers counters are used for storing view_numbers in IParameters
+ int vtkViewers = 0;
+
+ // main cycle to store parameters of displayed objects
+ QList<SUIT_ViewManager*> lst;
+ QList<SUIT_ViewManager*>::Iterator it;
+ getApp()->viewManagers(lst);
+ for (it = lst.begin(); it != lst.end(); it++)
+ {
+ SUIT_ViewManager* vman = *it;
+ QString vType = vman->getType();
+
+ // saving VTK actors properties
+ if (vType == SVTK_Viewer::Type())
+ {
+ // store the clipping planes attached to the view manager
+ SMESHGUI_ClippingPlaneInfoList aClippingPlaneInfoList;
+ SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter = myClippingPlaneInfoMap.find( vman );
+ if( anIter != myClippingPlaneInfoMap.end() )
+ aClippingPlaneInfoList = anIter->second;
+
+ if( !aClippingPlaneInfoList.empty() ) {
+ SMESHGUI_ClippingPlaneInfoList::const_iterator anIter = aClippingPlaneInfoList.begin();
+ for( int anId = 0; anIter != aClippingPlaneInfoList.end(); anIter++, anId++ )
+ {
+ const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter;
+ SMESH::OrientedPlane* aPlane = aClippingPlaneInfo.Plane;
+
+ QString aPropertyName( "ClippingPlane" );
+ aPropertyName += gSeparator;
+ aPropertyName += QString::number( vtkViewers );
+ aPropertyName += gSeparator;
+ aPropertyName += QString::number( anId );
+
+ QString aPropertyValue = QString::number( (int)aPlane->GetOrientation() ).toLatin1().constData();
+ aPropertyValue += gDigitsSep;
+ aPropertyValue += QString::number( aPlane->GetDistance() ).toLatin1().constData();
+ aPropertyValue += gDigitsSep;
+ aPropertyValue += QString::number( aPlane->myAngle[0] ).toLatin1().constData();
+ aPropertyValue += gDigitsSep;
+ aPropertyValue += QString::number( aPlane->myAngle[1] ).toLatin1().constData();
+
+ ip->setProperty( aPropertyName.toStdString(), aPropertyValue.toStdString() );
+ }
+ }
+
+ QVector<SUIT_ViewWindow*> views = vman->getViews();
+ for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
+ {
+ if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
+ {
+ VTK::ActorCollectionCopy aCopy(vtkView->getRenderer()->GetActors());
+ vtkActorCollection* allActors = aCopy.GetActors();
+ allActors->InitTraversal();
+ while (vtkActor* actor = allActors->GetNextActor())
+ {
+ if (actor->GetVisibility()) // store only visible actors
+ {
+ SMESH_Actor* aSmeshActor = 0;
+ if (actor->IsA("SMESH_Actor"))
+ aSmeshActor = SMESH_Actor::SafeDownCast(actor);
+ if (aSmeshActor && aSmeshActor->hasIO())
+ {
+ Handle(SALOME_InteractiveObject) io = aSmeshActor->getIO();
+ if (io->hasEntry())
+ {
+ // entry is "encoded" = it does NOT contain component adress,
+ // since it is a subject to change on next component loading
+ std::string entry = ip->encodeEntry(io->getEntry(), componentName);
+
+ std::string param, vtkParam = vType.toLatin1().data();
+ vtkParam += gSeparator;
+ vtkParam += QString::number(vtkViewers).toLatin1().data();
+ vtkParam += gSeparator;
+
+ // Visibility
+ param = vtkParam + "Visibility";
+ ip->setParameter(entry, param, "On");
+
+ // Representation
+ param = vtkParam + "Representation";
+ ip->setParameter(entry, param, QString::number
+ ((int)aSmeshActor->GetRepresentation()).toLatin1().data());
+
+ // IsShrunk
+ param = vtkParam + "IsShrunk";
+ ip->setParameter(entry, param, QString::number
+ ((int)aSmeshActor->IsShrunk()).toLatin1().data());
+
+ // Displayed entities
+ unsigned int aMode = aSmeshActor->GetEntityMode();
+ bool isE = aMode & SMESH_Actor::eEdges;
+ bool isF = aMode & SMESH_Actor::eFaces;
+ bool isV = aMode & SMESH_Actor::eVolumes;
+ bool is0d = aMode & SMESH_Actor::e0DElements;
+ bool isB = aMode & SMESH_Actor::eBallElem;
+
+ QString modeStr ("e");
+ modeStr += gDigitsSep; modeStr += QString::number(isE);
+ modeStr += gDigitsSep; modeStr += "f";
+ modeStr += gDigitsSep; modeStr += QString::number(isF);
+ modeStr += gDigitsSep; modeStr += "v";
+ modeStr += gDigitsSep; modeStr += QString::number(isV);
+ modeStr += gDigitsSep; modeStr += "0d";
+ modeStr += gDigitsSep; modeStr += QString::number(is0d);
+ modeStr += gDigitsSep; modeStr += "b";
+ modeStr += gDigitsSep; modeStr += QString::number(isB);
+
+ param = vtkParam + "Entities";
+ ip->setParameter(entry, param, modeStr.toLatin1().data());
+
+ // Colors
+ double r, g, b;
+ int delta;
+
+ aSmeshActor->GetSufaceColor(r, g, b, delta);
+ QStringList colorStr;
+ colorStr << "surface";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+
+ colorStr << "backsurface";
+ colorStr << QString::number(delta);
+
+ aSmeshActor->GetVolumeColor(r, g, b, delta);
+ colorStr << "volume";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+ colorStr << QString::number(delta);
+
+ aSmeshActor->GetEdgeColor(r, g, b);
+ colorStr << "edge";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+
+ aSmeshActor->GetNodeColor(r, g, b);
+ colorStr << "node";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+
+ aSmeshActor->GetOutlineColor(r, g, b);
+ colorStr << "outline";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+
+ aSmeshActor->Get0DColor(r, g, b);
+ colorStr << "elem0d";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+
+ aSmeshActor->GetBallColor(r, g, b);
+ colorStr << "ball";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+
+ aSmeshActor->GetFacesOrientationColor(r, g, b);
+ colorStr << "orientation";
+ colorStr << QString::number(r);
+ colorStr << QString::number(g);
+ colorStr << QString::number(b);
+
+ param = vtkParam + "Colors";
+ ip->setParameter(entry, param, qPrintable(colorStr.join(gDigitsSep)));
+
+ // Sizes
+ QStringList sizeStr;
+ sizeStr << "line";
+ sizeStr << QString::number((int)aSmeshActor->GetLineWidth());
+ sizeStr << "outline";
+ sizeStr << QString::number((int)aSmeshActor->GetOutlineWidth());
+ sizeStr << "elem0d";
+ sizeStr << QString::number((int)aSmeshActor->Get0DSize());
+ sizeStr << "ball";
+ sizeStr << QString::number((int)aSmeshActor->GetBallSize());
+ sizeStr << "shrink";
+ sizeStr << QString::number(aSmeshActor->GetShrinkFactor());
+ sizeStr << "orientation";
+ sizeStr << QString::number(aSmeshActor->GetFacesOrientationScale());
+ sizeStr << QString::number(aSmeshActor->GetFacesOrientation3DVectors());
+
+ param = vtkParam + "Sizes";
+ ip->setParameter(entry, param, qPrintable(sizeStr.join(gDigitsSep)));
+
+ // Point marker
+ QString markerStr;
+
+ VTK::MarkerType aMarkerType = aSmeshActor->GetMarkerType();
+ if( aMarkerType == VTK::MT_USER ) {
+ markerStr += "custom";
+ markerStr += gDigitsSep;
+ markerStr += QString::number( aSmeshActor->GetMarkerTexture() );
+ }
+ else {
+ markerStr += "std";
+ markerStr += gDigitsSep;
+ markerStr += QString::number( (int)aMarkerType );
+ markerStr += gDigitsSep;
+ markerStr += QString::number( (int)aSmeshActor->GetMarkerScale() );
+ }
+
+ param = vtkParam + "PointMarker";
+ ip->setParameter(entry, param, markerStr.toLatin1().data());
+
+ // Opacity
+ param = vtkParam + "Opacity";
+ ip->setParameter(entry, param,
+ QString::number(aSmeshActor->GetOpacity()).toLatin1().data());
+
+ // Clipping
+ param = vtkParam + "ClippingPlane";
+ int aPlaneId = 0;
+ if( !aClippingPlaneInfoList.empty() ) {
+ SMESHGUI_ClippingPlaneInfoList::const_iterator anIter1 = aClippingPlaneInfoList.begin();
+ for( int anId = 0; anIter1 != aClippingPlaneInfoList.end(); anIter1++, anId++ )
+ {
+ const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter1;
+ std::list<vtkActor*> anActorList = aClippingPlaneInfo.ActorList;
+ SMESH::TActorList::iterator anIter2 = anActorList.begin();
+ for ( ; anIter2 != anActorList.end(); anIter2++ ) {
+ if( aSmeshActor == *anIter2 ) {
+ ip->setParameter( entry, param + QString::number( ++aPlaneId ).toLatin1().constData(),
+ QString::number( anId ).toLatin1().constData() );
+ break;
+ }
+ }
+ }
+ }
+ if( aPlaneId == 0 )
+ ip->setParameter( entry, param, "Off" );
+ } // if (io->hasEntry())
+ } // SMESH_Actor && hasIO
+ } // isVisible
+ } // while.. actors traversal
+ } // if (vtkView)
+ } // for (views)
+ vtkViewers++;
+ } // if (SVTK view model)
+ } // for (viewManagers)
+}
+
+// data structures for clipping planes processing
+typedef struct {
+ int Id;
+ vtkIdType Orientation;
+ double Distance;
+ double Angle[2];
+} TPlaneData;
+typedef std::list<TPlaneData> TPlaneDataList;
+typedef std::map<int, TPlaneDataList> TPlaneDataMap;
+
+typedef std::list<vtkActor*> TActorList;
+typedef struct {
+ int PlaneId;
+ TActorList ActorList;
+ SUIT_ViewManager* ViewManager;
+} TPlaneInfo;
+typedef std::list<TPlaneInfo> TPlaneInfoList;
+typedef std::map<int, TPlaneInfoList> TPlaneInfoMap;
+
+/*!
+ * \brief Restore visual parameters
+ *
+ * This method is called after the study document is opened.
+ * Restore visual parameters from AttributeParameter attribue(s)
+ */
+void SMESHGUI::restoreVisualParameters (int savePoint)
+{
+ // localizing
+ Kernel_Utils::Localizer loc;
+
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
+ if (!appStudy || !appStudy->studyDS())
+ return;
+ _PTR(Study) studyDS = appStudy->studyDS();
+
+ // componentName is used for encoding of entries when storing them in IParameters
+ std::string componentName = myComponentSMESH->ComponentDataType();
+ //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
+ //if (!aSComponent) return;
+
+ // IParameters
+ _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
+ componentName.c_str(),
+ savePoint);
+ _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
+
+ // restore map of custom markers and map of clipping planes
+ VTK::MarkerMap& aMarkerMap = myMarkerMap[ studyDS->StudyId() ];
+ TPlaneDataMap aPlaneDataMap;
+
+ std::vector<std::string> properties = ip->getProperties();
+ for (std::vector<std::string>::iterator propIt = properties.begin(); propIt != properties.end(); ++propIt)
+ {
+ std::string property = *propIt;
+ QString aPropertyName( property.c_str() );
+ QString aPropertyValue( ip->getProperty( property ).c_str() );
+
+ QStringList aPropertyNameList = aPropertyName.split( gSeparator, QString::SkipEmptyParts );
+ if( aPropertyNameList.isEmpty() )
+ continue;
+
+ QString aPropertyType = aPropertyNameList[0];
+ if( aPropertyType == "texture" )
+ {
+ if( aPropertyNameList.size() != 2 )
+ continue;
+
+ bool ok = false;
+ int anId = aPropertyNameList[1].toInt( &ok );
+ if( !ok || anId < 1 )
+ continue;
+
+ QStringList aPropertyValueList = aPropertyValue.split( gPathSep, QString::SkipEmptyParts );
+ if( aPropertyValueList.size() != 2 )
+ continue;
+
+ std::string aMarkerFileName = aPropertyValueList[0].toStdString();
+ QString aMarkerTextureString = aPropertyValueList[1];
+ QStringList aMarkerTextureStringList = aMarkerTextureString.split( gDigitsSep, QString::SkipEmptyParts );
+ if( aMarkerTextureStringList.size() != 3 )
+ continue;
+
+ ok = false;
+ ushort aWidth = aMarkerTextureStringList[0].toUShort( &ok );
+ if( !ok )
+ continue;
+
+ ok = false;
+ ushort aHeight = aMarkerTextureStringList[1].toUShort( &ok );
+ if( !ok )
+ continue;
+
+ VTK::MarkerTexture aMarkerTexture;
+ aMarkerTexture.push_back( aWidth );
+ aMarkerTexture.push_back( aHeight );
+
+ QString aMarkerTextureData = aMarkerTextureStringList[2];
+ for( int i = 0, n = aMarkerTextureData.length(); i < n; i++ )
+ {
+ QChar aChar = aMarkerTextureData.at( i );
+ if( aChar.isDigit() )
+ aMarkerTexture.push_back( aChar.digitValue() );
+ }
+
+ aMarkerMap[ anId ] = VTK::MarkerData( aMarkerFileName, aMarkerTexture );
+ }
+ else if( aPropertyType == "ClippingPlane" )
+ {
+ if( aPropertyNameList.size() != 3 )
+ continue;
+
+ bool ok = false;
+ int aViewId = aPropertyNameList[1].toInt( &ok );
+ if( !ok || aViewId < 0 )
+ continue;
+
+ ok = false;
+ int aClippingPlaneId = aPropertyNameList[2].toInt( &ok );
+ if( !ok || aClippingPlaneId < 0 )
+ continue;
+
+ QStringList aPropertyValueList = aPropertyValue.split( gDigitsSep, QString::SkipEmptyParts );
+ if( aPropertyValueList.size() != 4 )
+ continue;
+
+ TPlaneData aPlaneData;
+ aPlaneData.Id = aClippingPlaneId;
+
+ ok = false;
+ aPlaneData.Orientation = aPropertyValueList[0].toInt( &ok );
+ if( !ok )
+ continue;
+
+ ok = false;
+ aPlaneData.Distance = aPropertyValueList[1].toDouble( &ok );
+ if( !ok )
+ continue;
+
+ ok = false;
+ aPlaneData.Angle[0] = aPropertyValueList[2].toDouble( &ok );
+ if( !ok )
+ continue;
+
+ ok = false;
+ aPlaneData.Angle[1] = aPropertyValueList[3].toDouble( &ok );
+ if( !ok )
+ continue;
+
+ TPlaneDataList& aPlaneDataList = aPlaneDataMap[ aViewId ];
+ aPlaneDataList.push_back( aPlaneData );
+ }
+ }
+
+ TPlaneInfoMap aPlaneInfoMap;
+
+ std::vector<std::string> entries = ip->getEntries();
+
+ for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
+ {
+ // entry is a normal entry - it should be "decoded" (setting base adress of component)
+ QString entry (ip->decodeEntry(*entIt).c_str());
+
+ // Check that the entry corresponds to a real object in the Study
+ // as the object may be deleted or modified after the visual state is saved.
+ _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
+ if (!so) continue; //Skip the not existent entry
+
+ std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
+ std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
+
+ std::vector<std::string>::iterator namesIt = paramNames.begin();
+ std::vector<std::string>::iterator valuesIt = paramValues.begin();
+
+ // actors are stored in a map after displaying of them for
+ // quicker access in the future: map < viewID to actor >
+ NCollection_DataMap<int, SMESH_Actor*> vtkActors;
+
+ for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
+ {
+ // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
+ // '_' is used as separator and should not be used in viewer type or parameter names.
+ QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
+ if (lst.size() != 3)
+ continue;
+
+ QString viewerTypStr = lst[0];
+ QString viewIndexStr = lst[1];
+ QString paramNameStr = lst[2];
+
+ bool ok;
+ int viewIndex = viewIndexStr.toUInt(&ok);
+ if (!ok) // bad conversion of view index to integer
+ continue;
+
+ // viewers
+ if (viewerTypStr == SVTK_Viewer::Type())
+ {
+ SMESH_Actor* aSmeshActor = 0;
+ if (vtkActors.IsBound(viewIndex))
+ aSmeshActor = vtkActors.Find(viewIndex);
+
+ QList<SUIT_ViewManager*> lst;
+ getApp()->viewManagers(viewerTypStr, lst);
+
+ // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
+ SUIT_ViewManager* vman = NULL;
+ if (viewIndex >= 0 && viewIndex < lst.count())
+ vman = lst.at(viewIndex);
+
+ if (paramNameStr == "Visibility")
+ {
+ if (!aSmeshActor && displayer() && vman)
+ {
+ SUIT_ViewModel* vmodel = vman->getViewModel();
+ // SVTK view model can be casted to SALOME_View
+ displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
+
+ // store displayed actor in a temporary map for quicker
+ // access later when restoring other parameters
+ SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
+ vtkRenderer* Renderer = vtkView->getRenderer();
+ VTK::ActorCollectionCopy aCopy(Renderer->GetActors());
+ vtkActorCollection* theActors = aCopy.GetActors();
+ theActors->InitTraversal();
+ bool isFound = false;
+ vtkActor *ac = theActors->GetNextActor();
+ for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
+ if (ac->IsA("SMESH_Actor")) {
+ SMESH_Actor* aGeomAc = SMESH_Actor::SafeDownCast(ac);
+ if (aGeomAc->hasIO()) {
+ Handle(SALOME_InteractiveObject) io =
+ Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
+ if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
+ isFound = true;
+ vtkActors.Bind(viewIndex, aGeomAc);
+ }
+ }
+ }
+ }
+ }
+ } // if (paramNameStr == "Visibility")
+ else
+ {
+ // the rest properties "work" with SMESH_Actor
+ if (aSmeshActor)
+ {
+ QString val ((*valuesIt).c_str());
+
+ // Representation
+ if (paramNameStr == "Representation") {
+ aSmeshActor->SetRepresentation((SMESH_Actor::EReperesent)val.toInt());
+ }
+ // IsShrunk
+ else if (paramNameStr == "IsShrunk") {
+ if (val.toInt()) {
+ if (!aSmeshActor->IsShrunk())
+ aSmeshActor->SetShrink();
+ }
+ else {
+ if (aSmeshActor->IsShrunk())
+ aSmeshActor->UnShrink();
+ }
+ }
+ // Displayed entities
+ else if (paramNameStr == "Entities") {
+ QStringList mode = val.split(gDigitsSep, QString::SkipEmptyParts);
+ int aEntityMode = SMESH_Actor::eAllEntity;
+ for ( int i = 0; i < mode.count(); i+=2 ) {
+ if ( i < mode.count()-1 ) {
+ QString type = mode[i];
+ bool val = mode[i+1].toInt();
+ if ( type == "e" && !val )
+ aEntityMode = aEntityMode & ~SMESH_Actor::eEdges;
+ else if ( type == "f" && !val )
+ aEntityMode = aEntityMode & ~SMESH_Actor::eFaces;
+ else if ( type == "v" && !val )
+ aEntityMode = aEntityMode & ~SMESH_Actor::eVolumes;
+ else if ( type == "0d" && !val )
+ aEntityMode = aEntityMode & ~SMESH_Actor::e0DElements;
+ else if ( type == "b" && !val )
+ aEntityMode = aEntityMode & ~SMESH_Actor::eBallElem;
+ }
+ }
+ aSmeshActor->SetEntityMode( aEntityMode );
+ }
+ // Colors
+ else if (paramNameStr == "Colors") {
+ QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
+ QColor nodeColor;
+ QColor edgeColor;
+ QColor faceColor;
+ QColor volumeColor;
+ QColor elem0dColor;
+ QColor ballColor;
+ QColor outlineColor;
+ QColor orientationColor;
+ int deltaF;
+ int deltaV;
+ QColor c;
+ double r, g, b;
+ bool bOk;
+ // below lines are required to get default values for delta coefficients
+ // of backface color for faces and color of reversed volumes
+ SMESH::GetColor( "SMESH", "fill_color", c, deltaF, "0,170,255|-100" );
+ SMESH::GetColor( "SMESH", "volume_color", c, deltaV, "255,0,170|-100" );
+ for ( int i = 0; i < colors.count(); i++ ) {
+ QString type = colors[i];
+ if ( type == "surface" ) {
+ // face color is set by 3 values r:g:b, where
+ // - r,g,b - is rgb color components
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ faceColor.setRgbF( r, g, b );
+ i += 3;
+ }
+ else if ( type == "backsurface" ) {
+ // backface color can be defined in several ways
+ // - in old versions, it is set as rgb triple r:g:b - this was is unsupported now
+ // - in latest versions, it is set as delta coefficient
+ bool rgbOk = false, deltaOk;
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ int delta = colors[i+1].toInt( &deltaOk );
+ i++; // shift index
+ if ( i+1 < colors.count() ) // index is shifted to 1
+ g = colors[i+1].toDouble( &rgbOk );
+ if ( rgbOk ) i++; // shift index
+ if ( rgbOk && i+1 < colors.count() ) // index is shifted to 2
+ b = colors[i+1].toDouble( &rgbOk );
+ if ( rgbOk ) i++;
+ // - as currently there's no way to set directly backsurface color as it was before,
+ // we ignore old dump where r,g,b triple was set
+ // - also we check that delta parameter is set properly
+ if ( !rgbOk && deltaOk )
+ deltaF = delta;
+ }
+ else if ( type == "volume" ) {
+ // volume color is set by 4 values r:g:b:delta, where
+ // - r,g,b - is a normal volume rgb color components
+ // - delta - is a reversed volume color delta coefficient
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+4 >= colors.count() ) break; // format error
+ int delta = colors[i+4].toInt( &bOk );
+ if ( !bOk ) break; // format error
+ volumeColor.setRgbF( r, g, b );
+ deltaV = delta;
+ i += 4;
+ }
+ else if ( type == "edge" ) {
+ // edge color is set by 3 values r:g:b, where
+ // - r,g,b - is rgb color components
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ edgeColor.setRgbF( r, g, b );
+ i += 3;
+ }
+ else if ( type == "node" ) {
+ // node color is set by 3 values r:g:b, where
+ // - r,g,b - is rgb color components
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ nodeColor.setRgbF( r, g, b );
+ i += 3;
+ }
+ else if ( type == "elem0d" ) {
+ // 0d element color is set by 3 values r:g:b, where
+ // - r,g,b - is rgb color components
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ elem0dColor.setRgbF( r, g, b );
+ i += 3;
+ }
+ else if ( type == "ball" ) {
+ // ball color is set by 3 values r:g:b, where
+ // - r,g,b - is rgb color components
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ ballColor.setRgbF( r, g, b );
+ i += 3;
+ }
+ else if ( type == "outline" ) {
+ // outline color is set by 3 values r:g:b, where
+ // - r,g,b - is rgb color components
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ outlineColor.setRgbF( r, g, b );
+ i += 3;
+ }
+ else if ( type == "orientation" ) {
+ // orientation color is set by 3 values r:g:b, where
+ // - r,g,b - is rgb color components
+ if ( i+1 >= colors.count() ) break; // format error
+ r = colors[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= colors.count() ) break; // format error
+ g = colors[i+2].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+3 >= colors.count() ) break; // format error
+ b = colors[i+3].toDouble( &bOk ); if ( !bOk ) break; // format error
+ orientationColor.setRgbF( r, g, b );
+ i += 3;
+ }
+ }
+ // node color
+ if ( nodeColor.isValid() )
+ aSmeshActor->SetNodeColor( nodeColor.redF(), nodeColor.greenF(), nodeColor.blueF() );
+ // edge color
+ if ( edgeColor.isValid() )
+ aSmeshActor->SetEdgeColor( edgeColor.redF(), edgeColor.greenF(), edgeColor.blueF() );
+ // face color
+ if ( faceColor.isValid() )
+ aSmeshActor->SetSufaceColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
+ // volume color
+ if ( volumeColor.isValid() )
+ aSmeshActor->SetVolumeColor( volumeColor.redF(), volumeColor.greenF(), volumeColor.blueF(), deltaV );
+ else if ( faceColor.isValid() ) // backward compatibility (no separate color for volumes)
+ aSmeshActor->SetVolumeColor( faceColor.redF(), faceColor.greenF(), faceColor.blueF(), deltaF );
+ // 0d element color
+ if ( elem0dColor.isValid() )
+ aSmeshActor->Set0DColor( elem0dColor.redF(), elem0dColor.greenF(), elem0dColor.blueF() );
+ // ball color
+ if ( ballColor.isValid() )
+ aSmeshActor->SetBallColor( ballColor.redF(), ballColor.greenF(), ballColor.blueF() );
+ // outline color
+ if ( outlineColor.isValid() )
+ aSmeshActor->SetOutlineColor( outlineColor.redF(), outlineColor.greenF(), outlineColor.blueF() );
+ // orientation color
+ if ( orientationColor.isValid() )
+ aSmeshActor->SetFacesOrientationColor( orientationColor.redF(), orientationColor.greenF(), orientationColor.blueF() );
+ }
+ // Sizes
+ else if (paramNameStr == "Sizes") {
+ QStringList sizes = val.split(gDigitsSep, QString::SkipEmptyParts);
+ bool bOk;
+ int lineWidth = -1;
+ int outlineWidth = -1;
+ int elem0dSize = -1;
+ int ballSize = -1;
+ double shrinkSize = -1;
+ double orientationSize = -1;
+ bool orientation3d = false;
+ for ( int i = 0; i < sizes.count(); i++ ) {
+ QString type = sizes[i];
+ if ( type == "line" ) {
+ // line (wireframe) width is given as single integer value
+ if ( i+1 >= sizes.count() ) break; // format error
+ int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break; // format error
+ lineWidth = v;
+ i++;
+ }
+ if ( type == "outline" ) {
+ // outline width is given as single integer value
+ if ( i+1 >= sizes.count() ) break; // format error
+ int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break; // format error
+ outlineWidth = v;
+ i++;
+ }
+ else if ( type == "elem0d" ) {
+ // 0d element size is given as single integer value
+ if ( i+1 >= sizes.count() ) break; // format error
+ int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break; // format error
+ elem0dSize = v;
+ i++;
+ }
+ else if ( type == "ball" ) {
+ // ball size is given as single integer value
+ if ( i+1 >= sizes.count() ) break; // format error
+ int v = sizes[i+1].toInt( &bOk ); if ( !bOk ) break; // format error
+ ballSize = v;
+ i++;
+ }
+ else if ( type == "shrink" ) {
+ // shrink factor is given as single floating point value
+ if ( i+1 >= sizes.count() ) break; // format error
+ double v = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ shrinkSize = v;
+ i++;
+ }
+ else if ( type == "orientation" ) {
+ // orientation vectors are specified by two values size:3d, where
+ // - size - is a floating point value specifying scale factor
+ // - 3d - is a boolean
+ if ( i+1 >= sizes.count() ) break; // format error
+ double v1 = sizes[i+1].toDouble( &bOk ); if ( !bOk ) break; // format error
+ if ( i+2 >= sizes.count() ) break; // format error
+ int v2 = sizes[i+2].toInt( &bOk ); if ( !bOk ) break; // format error
+ orientationSize = v1;
+ orientation3d = (bool)v2;
+ i += 2;
+ }
+ }
+ // line (wireframe) width
+ if ( lineWidth > 0 )
+ aSmeshActor->SetLineWidth( lineWidth );
+ // outline width
+ if ( outlineWidth > 0 )
+ aSmeshActor->SetOutlineWidth( outlineWidth );
+ else if ( lineWidth > 0 ) // backward compatibility (no separate width for outlines)
+ aSmeshActor->SetOutlineWidth( lineWidth );
+ // 0d element size
+ if ( elem0dSize > 0 )
+ aSmeshActor->Set0DSize( elem0dSize );
+ // ball size
+ if ( ballSize > 0 )
+ aSmeshActor->SetBallSize( ballSize );
+ // shrink factor
+ if ( shrinkSize > 0 )
+ aSmeshActor->SetShrinkFactor( shrinkSize );
+ // orientation vectors
+ if ( orientationSize > 0 ) {
+ aSmeshActor->SetFacesOrientationScale( orientationSize );
+ aSmeshActor->SetFacesOrientation3DVectors( orientation3d );
+ }
+ }
+ // Point marker
+ else if (paramNameStr == "PointMarker") {
+ QStringList data = val.split(gDigitsSep, QString::SkipEmptyParts);
+ if( data.count() >= 2 ) {
+ bool ok = false;
+ int aParam1 = data[1].toInt( &ok );
+ if( ok ) {
+ if( data[0] == "std" && data.count() == 3 ) {
+ int aParam2 = data[2].toInt( &ok );
+ aSmeshActor->SetMarkerStd( (VTK::MarkerType)aParam1, (VTK::MarkerScale)aParam2 );
+ }
+ else if( data[0] == "custom" ) {
+ VTK::MarkerMap::const_iterator markerIt = aMarkerMap.find( aParam1 );
+ if( markerIt != aMarkerMap.end() ) {
+ VTK::MarkerData aMarkerData = markerIt->second;
+ aSmeshActor->SetMarkerTexture( aParam1, aMarkerData.second );
+ }
+ }
+ }
+ }
+ }
+ // Opacity
+ else if (paramNameStr == "Opacity") {
+ aSmeshActor->SetOpacity(val.toFloat());
+ }
+ // Clipping
+ else if (paramNameStr.startsWith("ClippingPlane")) {
+ QStringList vals = val.split(gDigitsSep, QString::SkipEmptyParts);
+ // old format - val looks like "Off" or "0:0.5:0:0" (orientation, distance, two angles)
+ // new format - val looks like "Off" or "0" (plane id)
+ // (note: in new format "Off" value is used only for consistency,
+ // so it is processed together with values in old format)
+ bool anIsOldFormat = ( vals.count() == 4 || val == "Off" );
+ if( anIsOldFormat ) {
+ if (paramNameStr == "ClippingPlane1" || val == "Off")
+ aSmeshActor->RemoveAllClippingPlanes();
+ if (val != "Off") {
+ SMESH::Orientation anOrientation = (SMESH::Orientation)vals[0].toInt();
+ double aDistance = vals[1].toFloat();
+ double anAngle[2];
+ anAngle[0] = vals[2].toFloat();
+ anAngle[1] = vals[3].toFloat();
+
+ QList<SUIT_ViewManager*> lst;
+ getApp()->viewManagers(viewerTypStr, lst);
+ // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
+ if (viewIndex >= 0 && viewIndex < lst.count()) {
+ SUIT_ViewManager* vman = lst.at(viewIndex);
+ SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
+
+ SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ vman ];
+
+ SMESH::TActorList anActorList;
+ anActorList.push_back( aSmeshActor );
+ SMESH::OrientedPlane* aPlane =
+ SMESHGUI_ClippingDlg::AddPlane(anActorList, vtkView, anOrientation, aDistance, anAngle);
+ if( aPlane ) {
+ SMESH::ClippingPlaneInfo aClippingPlaneInfo;
+ aClippingPlaneInfo.Plane = aPlane;
+ aClippingPlaneInfo.ActorList = anActorList;
+ aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
+ }
+ }
+ }
+ }
+ else {
+ bool ok = false;
+ int aPlaneId = val.toInt( &ok );
+ if( ok && aPlaneId >= 0 ) {
+ bool anIsDefinedPlane = false;
+ TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ viewIndex ];
+ TPlaneInfoList::iterator anIter = aPlaneInfoList.begin();
+ for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
+ TPlaneInfo& aPlaneInfo = *anIter;
+ if( aPlaneInfo.PlaneId == aPlaneId ) {
+ aPlaneInfo.ActorList.push_back( aSmeshActor );
+ anIsDefinedPlane = true;
+ break;
+ }
+ }
+ if( !anIsDefinedPlane ) {
+ TPlaneInfo aPlaneInfo;
+ aPlaneInfo.PlaneId = aPlaneId;
+ aPlaneInfo.ActorList.push_back( aSmeshActor );
+ aPlaneInfo.ViewManager = vman;
+
+ // to make the list sorted by plane id
+ anIter = aPlaneInfoList.begin();
+ for( ; anIter != aPlaneInfoList.end(); anIter++ ) {
+ const TPlaneInfo& aPlaneInfoRef = *anIter;
+ if( aPlaneInfoRef.PlaneId > aPlaneId )
+ break;
+ }
+ aPlaneInfoList.insert( anIter, aPlaneInfo );
+ }
+ }
+ }
+ }
+ } // if (aSmeshActor)
+ } // other parameters than Visibility
+ }
+ } // for names/parameters iterator
+ } // for entries iterator
+
+ // take into account planes with empty list of actors referred to them
+ QList<SUIT_ViewManager*> aVMList;
+ getApp()->viewManagers(SVTK_Viewer::Type(), aVMList);
+
+ TPlaneDataMap::const_iterator aPlaneDataIter = aPlaneDataMap.begin();
+ for( ; aPlaneDataIter != aPlaneDataMap.end(); aPlaneDataIter++ ) {
+ int aViewId = aPlaneDataIter->first;
+ if( aViewId >= 0 && aViewId < aVMList.count() ) {
+ SUIT_ViewManager* aViewManager = aVMList.at( aViewId );
+
+ const TPlaneDataList& aPlaneDataList = aPlaneDataIter->second;
+
+ TPlaneInfoList& aPlaneInfoList = aPlaneInfoMap[ aViewId ];
+ TPlaneDataList::const_iterator anIter2 = aPlaneDataList.begin();
+ for( ; anIter2 != aPlaneDataList.end(); anIter2++ ) {
+ const TPlaneData& aPlaneData = *anIter2;
+ int aPlaneId = aPlaneData.Id;
+
+ bool anIsFound = false;
+ TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
+ for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
+ const TPlaneInfo& aPlaneInfo = *anIter3;
+ if( aPlaneInfo.PlaneId == aPlaneId ) {
+ anIsFound = true;
+ break;
+ }
+ }
+
+ if( !anIsFound ) {
+ TPlaneInfo aPlaneInfo; // ActorList field is empty
+ aPlaneInfo.PlaneId = aPlaneId;
+ aPlaneInfo.ViewManager = aViewManager;
+
+ // to make the list sorted by plane id
+ TPlaneInfoList::iterator anIter4 = aPlaneInfoList.begin();
+ for( ; anIter4 != aPlaneInfoList.end(); anIter4++ ) {
+ const TPlaneInfo& aPlaneInfoRef = *anIter4;
+ if( aPlaneInfoRef.PlaneId > aPlaneId )
+ break;
+ }
+ aPlaneInfoList.insert( anIter4, aPlaneInfo );
+ }
+ }
+ }
+ }
+
+ // add clipping planes to actors according to the restored parameters
+ // and update the clipping plane map
+ TPlaneInfoMap::const_iterator anIter1 = aPlaneInfoMap.begin();
+ for( ; anIter1 != aPlaneInfoMap.end(); anIter1++ ) {
+ int aViewId = anIter1->first;
+ const TPlaneInfoList& aPlaneInfoList = anIter1->second;
+
+ TPlaneDataMap::const_iterator anIter2 = aPlaneDataMap.find( aViewId );
+ if( anIter2 == aPlaneDataMap.end() )
+ continue;
+ const TPlaneDataList& aPlaneDataList = anIter2->second;
+
+ TPlaneInfoList::const_iterator anIter3 = aPlaneInfoList.begin();
+ for( ; anIter3 != aPlaneInfoList.end(); anIter3++ ) {
+ const TPlaneInfo& aPlaneInfo = *anIter3;
+ int aPlaneId = aPlaneInfo.PlaneId;
+ const TActorList& anActorList = aPlaneInfo.ActorList;
+ SUIT_ViewManager* aViewManager = aPlaneInfo.ViewManager;
+ if( !aViewManager )
+ continue;
+
+ SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( aViewManager->getActiveView() );
+ if( !aViewWindow )
+ continue;
+
+ SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = myClippingPlaneInfoMap[ aViewManager ];
+
+ TPlaneDataList::const_iterator anIter4 = aPlaneDataList.begin();
+ for( ; anIter4 != aPlaneDataList.end(); anIter4++ ) {
+ const TPlaneData& aPlaneData = *anIter4;
+ if( aPlaneData.Id == aPlaneId ) {
+ SMESH::OrientedPlane* aPlane =
+ SMESHGUI_ClippingDlg::AddPlane( anActorList,
+ aViewWindow,
+ (SMESH::Orientation)aPlaneData.Orientation,
+ aPlaneData.Distance,
+ aPlaneData.Angle );
+ if( aPlane ) {
+ SMESH::ClippingPlaneInfo aClippingPlaneInfo;
+ aClippingPlaneInfo.Plane = aPlane;
+ aClippingPlaneInfo.ActorList = anActorList;
+ aClippingPlaneInfoList.push_back( aClippingPlaneInfo );
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ // update all VTK views
+ QList<SUIT_ViewManager*> lst;
+ getApp()->viewManagers(lst);
+ for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
+ SUIT_ViewModel* vmodel = (*it)->getViewModel();
+ if (vmodel && vmodel->getType() == SVTK_Viewer::Type()) {
+ SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
+ vtkView->getRenderer()->ResetCameraClippingRange();
+ vtkView->Repaint();
+ }
+ }
+}
+
+/*!
+ \brief Adds preferences for dfont of VTK viewer
+ \param label label
+ \param pIf group identifier
+ \param param parameter
+ \return identifier of preferences
+*/
+int SMESHGUI::addVtkFontPref( const QString& label, const int pId, const QString& param, const bool needSize )
+{
+ int tfont = addPreference( label, pId, LightApp_Preferences::Font, "SMESH", param );
+
+ setPreferenceProperty( tfont, "mode", QtxFontEdit::Custom );
+
+ QStringList fam;
+ fam.append( tr( "SMESH_FONT_ARIAL" ) );
+ fam.append( tr( "SMESH_FONT_COURIER" ) );
+ fam.append( tr( "SMESH_FONT_TIMES" ) );
+
+ setPreferenceProperty( tfont, "fonts", fam );
+
+ int f = QtxFontEdit::Family | QtxFontEdit::Bold | QtxFontEdit::Italic | QtxFontEdit::Shadow;
+ if ( needSize ) f = f | QtxFontEdit::Size;
+ setPreferenceProperty( tfont, "features", f );
+
+ return tfont;
+}
+
+/*!
+ \brief Actions after hypothesis edition
+ Updates object browser after hypothesis edition
+*/
+void SMESHGUI::onHypothesisEdit( int result )
+{
+ if( result == 1 )
+ SMESHGUI::Modified();
+ updateObjBrowser( true );
+}
+
+
+/*!
+ \brief Signal handler closing(SUIT_ViewWindow*) of a view
+ \param pview view being closed
+*/
+void SMESHGUI::onViewClosed( SUIT_ViewWindow* pview ) {
+#ifndef DISABLE_PLOT2DVIEWER
+ //Crear all Plot2d Viewers if need.
+ SMESH::ClearPlot2Viewers(pview);
+#endif
+}
+
+void SMESHGUI::message( const QString& msg )
+{
+ // dispatch message
+ QStringList data = msg.split("/");
+ if ( data.count() > 0 ) {
+ if ( data.first() == "mesh_loading" ) {
+ // get mesh entry
+ QString entry = data.count() > 1 ? data[1] : QString();
+ if ( entry.isEmpty() )
+ return;
+ // get study
+ _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() )->studyDS();
+ // get mesh name
+ _PTR(SObject) obj = study->FindObjectID( entry.toLatin1().constData() );
+ QString name;
+ if ( obj )
+ name = obj->GetName().c_str();
+ if ( name.isEmpty() )
+ return;
+
+ if ( data.last() == "stop" )
+ application()->putInfo( tr( "MESH_LOADING_MSG_FINISHED" ).arg( name ) );
+ else
+ application()->putInfo( tr( "MESH_LOADING_MSG" ).arg( name ) );
+ QApplication::processEvents();
+ }
+ }
+}
+
+/*!
+ \brief Connects or disconnects signals about activating and cloning view on the module slots
+ \param pview view which is connected/disconnected
+*/
+void SMESHGUI::connectView( const SUIT_ViewWindow* pview ) {
+ if(!pview)
+ return;
+
+ SUIT_ViewManager* viewMgr = pview->getViewManager();
+ if ( viewMgr ) {
+ disconnect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
+ this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
+
+ connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
+ this, SLOT( onViewClosed( SUIT_ViewWindow* ) ) );
+ }
+}
+
+/*!
+ \brief Return \c true if object can be renamed
+*/
+bool SMESHGUI::renameAllowed( const QString& entry) const {
+ SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
+ if( !anApp )
+ return false;
+
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
+ if( !appStudy )
+ return false;
+
+ SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry));
+
+ if(!obj)
+ return false;
+
+ if(appStudy->isComponent(entry) || obj->isReference())
+ return false;
+
+ // check type to prevent renaming of inappropriate objects
+ int aType = SMESHGUI_Selection::type(qPrintable(entry), SMESH::GetActiveStudyDocument());
+ if (aType == SMESH::MESH || aType == SMESH::GROUP ||
+ aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
+ aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
+ aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
+ aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM)
+ return true;
+
+ return false;
+}
+
+/*!
+ Rename object by entry.
+ \param entry entry of the object
+ \param name new name of the object
+ \brief Return \c true if rename operation finished successfully, \c false otherwise.
+*/
+bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
+
+ SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( application() );
+ if( !anApp )
+ return false;
+
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
+
+ if(!appStudy)
+ return false;
+
+ _PTR(Study) aStudy = appStudy->studyDS();
+
+ if(!aStudy)
+ return false;
+
+ bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
+ if ( aLocked ) {
+ SUIT_MessageBox::warning ( anApp->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
+ return false;
+ }
+
+
+ _PTR(SObject) obj = aStudy->FindObjectID( qPrintable(entry) );
+ _PTR(GenericAttribute) anAttr;
+ _PTR(AttributeName) aName;
+ if ( obj ) {
+ if ( obj->FindAttribute(anAttr, "AttributeName") ) {
+ aName = anAttr;
+ // check type to prevent renaming of inappropriate objects
+ int aType = SMESHGUI_Selection::type( qPrintable(entry), SMESH::GetActiveStudyDocument() );
+ if (aType == SMESH::MESH || aType == SMESH::GROUP ||
+ aType == SMESH::SUBMESH || aType == SMESH::SUBMESH_COMPOUND ||
+ aType == SMESH::SUBMESH_SOLID || aType == SMESH::SUBMESH_FACE ||
+ aType == SMESH::SUBMESH_EDGE || aType == SMESH::SUBMESH_VERTEX ||
+ aType == SMESH::HYPOTHESIS || aType == SMESH::ALGORITHM) {
+ if ( !name.isEmpty() ) {
+ SMESHGUI::GetSMESHGen()->SetName(obj->GetIOR().c_str(), qPrintable(name) );
+
+ // update name of group object and its actor
+ Handle(SALOME_InteractiveObject) IObject =
+ new SALOME_InteractiveObject ( qPrintable(entry), "SMESH", qPrintable(name) );
+
+ SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
+ if( !aGroupObject->_is_nil() ) {
+ aGroupObject->SetName( qPrintable(name) );
+ if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
+ anActor->setName( qPrintable(name) );
+ }
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}