+ if (section == "Geometry") {
+ SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
+ if (param == QString("SettingsGeomStep")) {
+ double spin_step = aResourceMgr->doubleValue(section, param, 100.);
+ EmitSignalDefaultStepValueChanged(spin_step);
+ }
+ else if (param == QString("toplevel_color")) {
+ QColor c = aResourceMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) );
+ GEOM_AISShape::setTopLevelColor(SalomeApp_Tools::color(c));
+ }
+ else if (param == QString("toplevel_dm")) {
+ GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)aResourceMgr->integerValue("Geometry", "toplevel_dm", 0));
+ }
+ }
+}
+
+LightApp_Displayer* GeometryGUI::displayer()
+{
+ if ( !myDisplayer )
+ myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
+ return myDisplayer;
+}
+
+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);
+
+ 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->getObjectMap(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;
+
+ 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 (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::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)
+}
+
+/*!
+ * \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: 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( GEOM::sectionSeparator(), QString::SkipEmptyParts);
+ if (lst.size() != 3)
+ continue;
+
+ 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::EdgesDirection )) {
+ aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::EdgesDirection ), 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->setObjectPropMap(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();
+ }
+ }
+}
+
+void GeometryGUI::onViewAboutToShow()
+{
+ SUIT_ViewWindow* window = application()->desktop()->activeWindow();
+ QAction* a = action( GEOMOp::OpSwitchVectors );
+ 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") );
+ } else {
+ a->setText ( tr("MEN_VECTOR_MODE_ON") );
+ a->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);
+
+ GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
+ if (!CORBA::is_nil(anObj)) {
+ aName->SetValue( name.toLatin1().data() ); // rename the SObject
+ anObj->SetName( name.toLatin1().data() ); // Rename the corresponding GEOM_Object
+ 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();
+ }
+ }