+
+void GeometryGUI::setLocalSelectionMode(const int mode)
+{
+ myLocalSelectionMode = mode;
+}
+
+int GeometryGUI::getLocalSelectionMode() const
+{
+ return myLocalSelectionMode;
+}
+
+const char gSeparator = '_'; // character used to separate parameter names
+const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
+
+/*!
+ * \brief Store visual parameters
+ *
+ * This method is called just before the study document is saved.
+ * Store visual parameters in AttributeParameter attribute(s)
+ */
+void GeometryGUI::storeVisualParameters (int savePoint)
+{
+ 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 = myComponentGeom->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);
+
+ QSet<QString> anEntriesToStoreShared;
+ QList<SUIT_ViewManager*> lst;
+ QList<SUIT_ViewManager*>::Iterator it;
+
+ // main cycle to store parameters of displayed objects
+ lst.clear();
+ getApp()->viewManagers(lst);
+ for (it = lst.begin(); it != lst.end(); it++) {
+ SUIT_ViewManager* vman = *it;
+ QString vType = vman->getType();
+ int aMgrId = vman->getGlobalId();
+ // saving VTK actors properties
+ QVector<SUIT_ViewWindow*> views = vman->getViews();
+ for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
+ const ObjMap& anObjects = appStudy->getObjectProperties(aMgrId);
+ ObjMap::ConstIterator o_it = anObjects.begin();
+ for (; o_it != anObjects.end(); o_it++) {
+ const PropMap& aProps = o_it.value();
+
+ //Check that object exists in the study
+ _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
+ if ( !obj || !(aProps.count() > 0))
+ continue;
+ // 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(o_it.key().toLatin1().data(), componentName);
+
+ _PTR(GenericAttribute) anAttr;
+ if (!obj->FindAttribute(anAttr, "AttributeIOR"))
+ continue;
+
+ // remember entry of object to store shared GEOM properties
+ // (e.g. dimension properties).
+ if ( vType == OCCViewer_Viewer::Type() )
+ {
+ anEntriesToStoreShared.insert( o_it.key() );
+ }
+
+ QString param, occParam = vType;
+ occParam += GEOM::sectionSeparator();
+ occParam += QString::number(aMgrId);
+ occParam += GEOM::sectionSeparator();
+
+ if (aProps.contains(GEOM::propertyName( GEOM::Visibility ))) {
+ param = occParam + GEOM::propertyName( GEOM::Visibility );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Visibility )).toBool() ? "On" : "Off");
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::DisplayMode ))) {
+ param = occParam + GEOM::propertyName( GEOM::DisplayMode );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::DisplayMode )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::Color ))) {
+ QColor c = aProps.value(GEOM::propertyName( GEOM::Color )).value<QColor>();
+ QStringList val;
+ val << QString::number(c.redF());
+ val << QString::number(c.greenF());
+ val << QString::number(c.blueF());
+ param = occParam + GEOM::propertyName( GEOM::Color );
+ ip->setParameter(entry, param.toStdString(), val.join( GEOM::subSectionSeparator()).toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::Texture ))) {
+ param = occParam + GEOM::propertyName( GEOM::Texture );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Texture )).toString().toStdString());
+ }
+
+ if (vType == SVTK_Viewer::Type()) {
+ if (aProps.contains(GEOM::propertyName( GEOM::Opacity ))) {
+ param = occParam + GEOM::propertyName( GEOM::Opacity );
+ ip->setParameter(entry, param.toStdString(), QString::number(1. - aProps.value(GEOM::propertyName( GEOM::Transparency )).toDouble()).toStdString());
+ }
+ } else if (vType == SOCC_Viewer::Type()) {
+ if (aProps.contains(GEOM::propertyName( GEOM::Transparency ))) {
+ param = occParam + GEOM::propertyName( GEOM::Transparency );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Transparency )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::TopLevel ))) {
+ param = occParam + GEOM::propertyName( GEOM::TopLevel );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::TopLevel )).toString().toStdString());
+ }
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::NbIsos ))) {
+ param = occParam + GEOM::propertyName( GEOM::NbIsos );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::NbIsos )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::EdgesDirection ))) {
+ param = occParam + GEOM::propertyName( GEOM::EdgesDirection );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::EdgesDirection )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::Vertices ))) {
+ param = occParam + GEOM::propertyName( GEOM::Vertices );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Vertices )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::ShowName ))) {
+ param = occParam + GEOM::propertyName( GEOM::ShowName );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::ShowName )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::Deflection ))) {
+ param = occParam + GEOM::propertyName( GEOM::Deflection );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Deflection )).toString().toStdString());
+ }
+
+ //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
+ if (aProps.contains(GEOM::propertyName( GEOM::PointMarker ))) {
+ param = occParam + GEOM::propertyName( GEOM::PointMarker );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::PointMarker )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::Material ))) {
+ param = occParam + GEOM::propertyName( GEOM::Material );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Material )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::LineWidth ))) {
+ param = occParam + GEOM::propertyName( GEOM::LineWidth );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::LineWidth )).toString().toStdString());
+ }
+
+ if (aProps.contains(GEOM::propertyName( GEOM::IsosWidth ))) {
+ param = occParam + GEOM::propertyName( GEOM::IsosWidth );
+ ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::IsosWidth )).toString().toStdString());
+ }
+ } // object iterator
+ } // for (views)
+ } // for (viewManagers)
+
+ // store dimension attributes of objects:
+ // since the displayed object always persists in property map, we remember the object entries
+ // on the passes when we store viewer related properties - to avoid extra iterations on GEOM component tree.
+ QString aDimensionParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::Dimensions );
+ QSet<QString>::ConstIterator aEntryIt = anEntriesToStoreShared.constBegin();
+ for ( ; aEntryIt != anEntriesToStoreShared.constEnd(); ++aEntryIt )
+ {
+ std::string aStudyEntry = (*aEntryIt).toLatin1().data();
+ std::string aStoreEntry = ip->encodeEntry( aStudyEntry, componentName);
+
+ GEOMGUI_DimensionProperty aDimensions( appStudy, aStudyEntry );
+
+ if ( aDimensions.GetNumber() == 0 )
+ {
+ continue;
+ }
+
+ ip->setParameter( aStoreEntry, aDimensionParam.toStdString(), ((QString)aDimensions).toLatin1().data() );
+ }
+}
+
+/*!
+ * \brief Restore visual parameters
+ *
+ * This method is called after the study document is opened.
+ * Restore visual parameters from AttributeParameter attribute(s)
+ */
+void GeometryGUI::restoreVisualParameters (int savePoint)
+{
+ 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 = myComponentGeom->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);
+
+ 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, GEOM_Actor* > vtkActors;
+ NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
+
+ QString viewerTypStr;
+ QString viewIndexStr;
+ int viewIndex;
+ QVector<PropMap> aListOfMap;
+
+ for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
+ {
+ // visual parameters are stored in strings as follows:
+ // 1) ViewerType_ViewIndex_ParamName
+ // 2) ViewerType_ParamName (shared for GEOM module)
+ // '_' is used as separator and should not be used in viewer type or parameter names.
+ QStringList lst = QString((*namesIt).c_str()).split( GEOM::sectionSeparator(), QString::SkipEmptyParts);
+
+ bool isShared = lst.size() == 2;
+ bool isViewer = lst.size() == 3;
+ if ( !isShared && !isViewer )
+ {
+ continue;
+ }
+
+ // shared visual parameters
+ if ( isShared )
+ {
+ QString aParamNameStr( lst[1] );
+ QString aValuesStr( (*valuesIt).c_str() );
+
+ // shared dimension properties are stored as attribute
+ if ( aParamNameStr == GEOM::propertyName( GEOM::Dimensions ) )
+ {
+ GEOMGUI_DimensionProperty aDimensionProp( aValuesStr );
+ aDimensionProp.SaveToAttribute( appStudy, entry.toLatin1().data() );
+ }
+
+ continue;
+ }
+
+ // per view visual parameters
+ viewerTypStr = lst[0];
+ viewIndexStr = lst[1];
+ QString paramNameStr = lst[2];
+
+ bool ok;
+ viewIndex = viewIndexStr.toUInt(&ok);
+ if (!ok) // bad conversion of view index to integer
+ continue;
+
+ if ((viewIndex + 1) > aListOfMap.count()) {
+ aListOfMap.resize(viewIndex + 1);
+ }
+
+ QString val((*valuesIt).c_str());
+ if (paramNameStr == GEOM::propertyName( GEOM::Visibility )) {
+ aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Visibility ), val == "On");
+ } else if (paramNameStr == GEOM::propertyName( GEOM::Opacity )) {
+ aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Transparency ), 1. - val.toDouble());
+ } else if (paramNameStr == GEOM::propertyName( GEOM::Transparency )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Transparency ), val.toDouble() );
+ } else if (paramNameStr == GEOM::propertyName( GEOM::TopLevel )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::TopLevel ), val == "true" || val == "1");
+ } else if (paramNameStr == GEOM::propertyName( GEOM::DisplayMode )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::DisplayMode ), val.toInt());
+ } else if (paramNameStr == GEOM::propertyName( GEOM::NbIsos )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::NbIsos ), val);
+ } else if (paramNameStr == GEOM::propertyName( GEOM::Color )) {
+ QStringList rgb = val.split(GEOM::subSectionSeparator());
+ if (rgb.count() == 3) {
+ QColor c = QColor::fromRgbF(rgb[0].toDouble(), rgb[1].toDouble(), rgb[2].toDouble());
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Color ), c);
+ }
+ } else if (paramNameStr == GEOM::propertyName( GEOM::Texture )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Texture ), val );
+ } else if (paramNameStr == GEOM::propertyName( GEOM::EdgesDirection )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::EdgesDirection ), val == "true" || val == "1");
+ } else if (paramNameStr == GEOM::propertyName( GEOM::Vertices )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Vertices ), val == "true" || val == "1");
+ } else if (paramNameStr == GEOM::propertyName( GEOM::ShowName )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::ShowName ), val == "true" || val == "1");
+ } else if (paramNameStr == GEOM::propertyName( GEOM::Deflection )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Deflection ), val.toDouble());
+ } else if (paramNameStr == GEOM::propertyName( GEOM::PointMarker )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::PointMarker ), val);
+ } else if (paramNameStr == GEOM::propertyName( GEOM::Material )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Material ), val);
+ } else if (paramNameStr == GEOM::propertyName( GEOM::LineWidth )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::LineWidth ), val.toInt());
+ } else if (paramNameStr == GEOM::propertyName( GEOM::IsosWidth )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::IsosWidth ), val.toInt());
+ }
+ } // for names/parameters iterator
+
+ QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
+
+ for (int index = 0; index < aListOfMap.count(); index++) {
+ appStudy->setObjectProperties(index, entry, aListOfMap[index]);
+
+ //Get Visibility property of the current PropMap
+ if (aListOfMap[index].value(GEOM::propertyName( GEOM::Visibility )) == 1) {
+ SUIT_ViewManager* vman = lst.at(index);
+ SUIT_ViewModel* vmodel = vman->getViewModel();
+ displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
+ }
+ }
+ } // for entries iterator
+
+ // update all VTK and OCC 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)
+ continue;
+ if (vmodel->getType() == SVTK_Viewer::Type()) {
+ SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
+ vtkView->getRenderer()->ResetCameraClippingRange();
+ vtkView->Repaint();
+ }
+ else if (vmodel->getType() == SOCC_Viewer::Type()) {
+ //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
+ SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
+ if (occVMod)
+ occVMod->Repaint();
+ }
+ }
+}
+
+// Compute current name mode of the viewer
+void UpdateNameMode( SalomeApp_Application* app )
+{
+ bool isMode = false;
+ SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
+ SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
+ GEOM_Displayer displayer( aStudy );
+ int aMgrId = viewWindow->getViewManager()->getGlobalId();
+
+ SALOME_View* window = displayer.GetActiveView();
+ if ( !window ) return;
+
+ SALOME_ListIO anIOlst;
+ window->GetVisible( anIOlst );
+
+ for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
+ Handle( SALOME_InteractiveObject ) io = It.Value();
+ QVariant v = aStudy->getObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), QVariant() );
+ bool isIONameMode = v.isValid() ? v.toBool() : false;
+ if( isIONameMode )
+ isMode = true;
+ }
+ viewWindow->setProperty( "NameMode", isMode );
+}
+
+void GeometryGUI::onViewAboutToShow()
+{
+ SUIT_ViewWindow* window = application()->desktop()->activeWindow();
+ QAction* a = action( GEOMOp::OpSwitchVectors );
+ QAction* aVerticesAction = action( GEOMOp::OpSwitchVertices );
+ QAction* aNameAction = action( GEOMOp::OpSwitchName );
+ if ( window ) {
+ a->setEnabled(true);
+ bool vmode = window->property("VectorsMode").toBool();
+ a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
+ aVerticesAction->setEnabled(true);
+ vmode = window->property("VerticesMode").toBool();
+ aVerticesAction->setText ( vmode == 1 ? tr( "MEN_VERTICES_MODE_OFF" ) : tr("MEN_VERTICES_MODE_ON") );
+ UpdateNameMode( getApp() );
+ aNameAction->setEnabled(true);
+ vmode = window->property("NameMode").toBool();
+ aNameAction->setText ( vmode == 1 ? tr( "MEN_NAME_MODE_OFF" ) : tr("MEN_NAME_MODE_ON") );
+ } else {
+ a->setText ( tr("MEN_VECTOR_MODE_ON") );
+ a->setEnabled(false);
+ aVerticesAction->setText ( tr("MEN_VERTICES_MODE_ON") );
+ aVerticesAction->setEnabled(false);
+ aNameAction->setText ( tr("MEN_NAME_MODE_ON") );
+ aNameAction->setEnabled(false);
+ }
+}
+
+/*!
+ \brief Return action by id
+ \param id identifier of the action
+ \return action
+*/
+QAction* GeometryGUI::getAction(const int id) {
+ return action(id);
+}
+
+/*!
+ \brief GEOM module message handler
+
+ This method can be re-implemented in the subclasses.
+ This is a GEOM module message handler.
+
+ \param msg the message received.
+*/
+void GeometryGUI::message(const QString& msg)
+{
+ // dispatch message
+ QStringList data = msg.split("/");
+ const int nbStrings = data.count();
+
+ if (nbStrings > 0) {
+ if (data[0] == "modified") {
+ // get mesh entry
+ QString anIOR = nbStrings > 1 ? data[1] : QString();
+
+ if ( anIOR.isEmpty() ) {
+ return;
+ }
+
+ // Get the geom object.
+ GEOM::GEOM_Object_ptr anObj = GeometryGUI::GetObjectFromIOR (anIOR);
+
+ // Clear the shape buffer
+ GeometryGUI::ClearShapeBuffer (anObj);
+ }
+ }
+}
+
+/*!
+ \brief Clears the shape buffer.
+
+ This is a static method. It clears the shape buffer.
+
+ \param theObj the object
+*/
+void GeometryGUI::ClearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
+{
+ if ( CORBA::is_nil( theObj ) )
+ return;
+
+ CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
+ TCollection_AsciiString asciiIOR( (char *)IOR.in() );
+ GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
+
+ SALOMEDSClient_StudyManager *aManager = SalomeApp_Application::studyMgr();
+
+ if (!aManager)
+ return;
+
+ _PTR(Study) aStudy = aManager->GetStudyByID(theObj->GetStudyID());
+
+ if ( !aStudy )
+ return;
+
+ _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
+ if ( !aSObj )
+ return;
+
+ _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
+ for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
+ _PTR(GenericAttribute) anAttr;
+ if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
+ _PTR(AttributeIOR) anIOR ( anAttr );
+ TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
+ GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
+ }
+ }
+}
+
+/*!
+ \brief Returns the object from IOR.
+
+ This is a static method. It returns the object from its IOR.
+
+ \param IOR object IOR
+ \return GEOM object.
+*/
+GEOM::GEOM_Object_ptr GeometryGUI::GetObjectFromIOR( const QString& IOR )
+{
+ GEOM::GEOM_Object_var geomObj;
+ if ( !IOR.isEmpty() ) {
+ CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object
+ ( IOR.toLatin1().constData() );
+ if ( !CORBA::is_nil( corbaObj ) )
+ geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
+ }
+ return geomObj._retn();
+}
+
+/*!
+ \brief Returns IOR of the object.
+
+ This is a static method. It returns the object's IOR.
+
+ \param object the GEOM object.
+ \return object's IOR.
+*/
+QString GeometryGUI::GetIORFromObject( GEOM::GEOM_Object_ptr object )
+{
+ QString IOR;
+ if ( !CORBA::is_nil( object ) ) {
+ CORBA::String_var anIOR =
+ SalomeApp_Application::orb()->object_to_string( object );
+ IOR = anIOR.in();
+ }
+ return IOR;
+}
+
+/*!
+ \brief Check if this object is can't be renamed in place
+
+ This method can be re-implemented in the subclasses.
+ Return true in case if object isn't reference or component (module root).
+
+ \param entry column id
+ \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
+*/
+bool GeometryGUI::renameAllowed( const QString& entry) const {
+
+ SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+ SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
+ SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
+
+ return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
+}
+
+/*!
+ 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 GeometryGUI::renameObject( const QString& entry, const QString& name)
+{
+ bool result = false;
+
+ SalomeApp_Application* app =
+ dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
+ SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
+
+ if (!appStudy)
+ return result;
+
+ _PTR(Study) aStudy = appStudy->studyDS();
+
+ if (!aStudy)
+ return result;
+
+ bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
+ if ( aLocked ) {
+ SUIT_MessageBox::warning ( app->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
+ return result;
+ }
+
+ _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
+ _PTR(GenericAttribute) anAttr;
+ if ( obj ) {
+ if ( obj->FindAttribute(anAttr, "AttributeName") ) {
+ _PTR(AttributeName) aName (anAttr);
+
+ aName->SetValue( name.toLatin1().data() ); // rename the SObject
+ GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
+ if (!CORBA::is_nil(anObj)) {
+ anObj->SetName( name.toLatin1().data() ); // Rename the corresponding GEOM_Object
+ emit SignalDependencyTreeRenameObject( anObj->GetEntry() );
+ }
+ result = true;
+ }
+ }
+ return result;
+}
+
+void GeometryGUI::updateMaterials()
+{
+ LightApp_Preferences* pref = preferences();
+ if ( pref ) {
+ QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
+ QString currentMaterial = SUIT_Session::session()->resourceMgr()->stringValue( "Geometry", "material" );
+ if ( !materials.contains( currentMaterial ) )
+ // user material set as default in the preferences, might be removed
+ SUIT_Session::session()->resourceMgr()->setValue( "Geometry", "material", QString( "Plastic" ) );
+
+ QtxPreferenceItem* prefItem = pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true );
+ if ( prefItem ) {
+ setPreferenceProperty( prefItem->id(),
+ "strings", materials );
+ prefItem->retrieve();
+ }
+ }
+}
+
+/*!
+ \brief Check if the module allows "drag" operation of its objects.
+
+ Overloaded from LightApp_Module class.
+
+ This function is a part of the general drag-n-drop mechanism.
+ The goal of this function is to check data object passed as a parameter
+ and decide if it can be dragged or no.
+
+ \param what data object being tested for drag operation
+ \return \c true if module allows dragging of the specified object
+ \sa isDropAccepted(), dropObjects()
+*/
+bool GeometryGUI::isDraggable( const SUIT_DataObject* what ) const
+{
+ // we allow dragging object under root and object from folder
+ int aLevel = what->level();
+ bool anObjectInFolder = false;
+ if ( aLevel > 2 ) {
+ const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( what );
+ if ( dataObj ) {
+ _PTR(SObject) aSO = dataObj->object();
+ if ( aSO ) {
+ _PTR(GenericAttribute) anAttr;
+ _PTR(SObject) aFatherSO = aSO->GetStudy()->GetUseCaseBuilder()->GetFather( aSO );
+ if ( aFatherSO && aFatherSO->FindAttribute(anAttr, "AttributeLocalID") ) {
+ _PTR(AttributeLocalID) aLocalID( anAttr );
+ anObjectInFolder = aLocalID->Value() == 999;
+ }
+ }
+ }
+ }
+ return aLevel == 2 || anObjectInFolder;
+}
+
+/*!
+ \brief Check if the module allows "drop" operation on the given object.
+
+ Overloaded from LightApp_Module class.
+
+ This function is a part of the general drag-n-drop mechanism.
+ The goal of this function is to check data object passed as a parameter
+ and decide if it can be used as a target for the "drop" operation.
+ The processing of the drop operation itself is done in the dropObjects() function.
+
+ \param where target data object
+ \return \c true if module supports dropping on the \a where data object
+ \sa isDraggable(), dropObjects()
+*/
+bool GeometryGUI::isDropAccepted( const SUIT_DataObject* where ) const
+{
+ // we allow dropping into folder and top-level GEOM object
+ int aLevel = where->level();
+ bool isFolder = false;
+ if ( aLevel > 1 ) {
+ const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( where );
+ if ( dataObj ) {
+ _PTR(SObject) aSO = dataObj->object();
+ if ( aSO ) {
+ _PTR(GenericAttribute) anAttr;
+ if ( aSO->FindAttribute(anAttr, "AttributeLocalID") ) {
+ _PTR(AttributeLocalID) aLocalID( anAttr );
+ isFolder = aLocalID->Value() == 999;
+ }
+ }
+ }
+ }
+ return aLevel == 1 || isFolder;
+}
+
+/*!
+ \brief Complete drag-n-drop operation.
+
+ Overloaded from LightApp_Module class.
+
+ This function is a part of the general drag-n-drop mechanism.
+ Its goal is to handle dropping of the objects being dragged according
+ to the chosen operation (move). The dropping is performed in the
+ context of the parent data object \a where and the \a row (position in the
+ children index) at which the data should be dropped. If \a row is equal to -1,
+ this means that objects are added to the end of the children list.
+
+ \param what objects being dropped
+ \param where target data object
+ \param row child index at which the drop operation is performed
+ \param action drag-n-drop operation (Qt::DropAction) - move
+
+ \sa isDraggable(), isDropAccepted()
+*/
+void GeometryGUI::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
+ const int row, Qt::DropAction action )
+{
+ if (action != Qt::CopyAction && action != Qt::MoveAction)
+ return; // unsupported action
+
+ // get parent object
+ SalomeApp_DataObject* dataObj = dynamic_cast<SalomeApp_DataObject*>( where );
+ if ( !dataObj ) return; // wrong parent
+ _PTR(SObject) parentObj = dataObj->object();
+
+ // Find the current Study and StudyBuilder
+ _PTR(Study) aStudy = parentObj->GetStudy();
+ _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
+ // collect all parents of the target node
+ QStringList parentIDs;
+ _PTR(SObject) parent = parentObj;
+ while( !parent->IsNull() ) {
+ parentIDs << parent->GetID().c_str();
+ parent = aUseCaseBuilder->GetFather(parent);
+ }
+
+ // collect objects being dropped
+ GEOM::object_list_var objects = new GEOM::object_list();
+ objects->length( what.count() );
+ int count = 0;
+ for ( int i = 0; i < what.count(); i++ ) {
+ dataObj = dynamic_cast<SalomeApp_DataObject*>( what[i] );
+ if ( !dataObj ) continue; // skip wrong objects
+ _PTR(SObject) sobj = dataObj->object();
+ // check that dropped object is not a parent of target object
+ if ( parentIDs.contains( sobj->GetID().c_str() ) ) {
+ return; // it's not allowed to move node into it's child
+ }
+ objects[i] = _CAST(SObject, sobj)->GetSObject();
+ count++;
+ }
+ objects->length( count );
+
+ // call engine function
+ GetGeomGen()->Move( objects.in(), // what
+ _CAST(SObject, parentObj)->GetSObject(), // where
+ row ); // row
+
+ // update Object browser
+ getApp()->updateObjectBrowser( false );
+}
+
+void GeometryGUI::emitDimensionsUpdated( QString entry )
+{
+ emit DimensionsUpdated( entry );
+}