+
+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;
+
+ std::string param,occParam = vType.toLatin1().data();
+ occParam += NAME_SEPARATOR;
+ occParam += QString::number(aMgrId).toLatin1().data();
+ occParam += NAME_SEPARATOR;
+
+ if(aProps.contains(VISIBILITY_PROP)) {
+ param = occParam + VISIBILITY_PROP;
+ ip->setParameter(entry, param, aProps.value(VISIBILITY_PROP).toInt() == 1 ? "On" : "Off");
+ }
+
+ if(aProps.contains(DISPLAY_MODE_PROP)) {
+ param = occParam + DISPLAY_MODE_PROP;
+ ip->setParameter(entry, param, QString::number(aProps.value(DISPLAY_MODE_PROP).toInt()).toLatin1().data());
+ }
+
+ if(aProps.contains(COLOR_PROP)) {
+ QColor c = aProps.value(COLOR_PROP).value<QColor>();
+ QString colorStr = QString::number(c.red()/255.);
+ colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.green()/255.);
+ colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.blue()/255.);
+ param = occParam + COLOR_PROP;
+ ip->setParameter(entry, param, colorStr.toLatin1().data());
+ }
+
+ if(vType == SVTK_Viewer::Type()) {
+ if(aProps.contains(OPACITY_PROP)) {
+ param = occParam + OPACITY_PROP;
+ ip->setParameter(entry, param, QString::number(1. - aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
+ }
+ } else if (vType == SOCC_Viewer::Type()) {
+ if(aProps.contains(TRANSPARENCY_PROP)) {
+ param = occParam + TRANSPARENCY_PROP;
+ ip->setParameter(entry, param, QString::number(aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
+ }
+
+ if(aProps.contains(TOP_LEVEL_PROP)) {
+ param = occParam + TOP_LEVEL_PROP;
+ Standard_Boolean val = aProps.value(TOP_LEVEL_PROP).value<Standard_Boolean>();
+ if (val == Standard_True)
+ ip->setParameter(entry, param, "1");
+ }
+ }
+
+ if(aProps.contains(ISOS_PROP)) {
+ param = occParam + ISOS_PROP;
+ ip->setParameter(entry, param, aProps.value(ISOS_PROP).toString().toLatin1().data());
+ }
+
+ if(aProps.contains(VECTOR_MODE_PROP)) {
+ param = occParam + VECTOR_MODE_PROP;
+ ip->setParameter(entry, param, QString::number(aProps.value(VECTOR_MODE_PROP).toInt()).toLatin1().data());
+ }
+
+ if(aProps.contains(DEFLECTION_COEFF_PROP)) {
+ param = occParam + DEFLECTION_COEFF_PROP;
+ ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data());
+ }
+
+ //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
+ if(aProps.contains(MARKER_TYPE_PROP)) {
+ param = occParam + MARKER_TYPE_PROP;
+ ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data());
+ }
+
+ if(aProps.contains(MATERIAL_PROP)) {
+ param = occParam + MATERIAL_PROP;
+ ip->setParameter(entry, param, aProps.value(MATERIAL_PROP).toString().toLatin1().data());
+ }
+
+ if(aProps.contains( EDGE_WIDTH_PROP )) {
+ param = occParam + EDGE_WIDTH_PROP;
+ ip->setParameter(entry, param, aProps.value(EDGE_WIDTH_PROP).toString().toLatin1().data());
+ }
+
+ if(aProps.contains( ISOS_WIDTH_PROP )) {
+ param = occParam + ISOS_WIDTH_PROP;
+ ip->setParameter(entry, param, aProps.value(ISOS_WIDTH_PROP).toString().toLatin1().data());
+ }
+ } // 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(NAME_SEPARATOR, 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 == VISIBILITY_PROP){
+ aListOfMap[viewIndex].insert(VISIBILITY_PROP, val == "On" ? 1 : 0);
+
+ } else if(paramNameStr == OPACITY_PROP) {
+ aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, 1. - val.toDouble());
+
+ } else if(paramNameStr == TRANSPARENCY_PROP) {
+ aListOfMap[viewIndex].insert( TRANSPARENCY_PROP, val.toDouble() );
+
+ } else if(paramNameStr == TOP_LEVEL_PROP) {
+ aListOfMap[viewIndex].insert( TRANSPARENCY_PROP, val == "1" ? Standard_True : Standard_False );
+
+ } else if(paramNameStr == DISPLAY_MODE_PROP) {
+ aListOfMap[viewIndex].insert( DISPLAY_MODE_PROP, val.toInt());
+
+ } else if(paramNameStr == ISOS_PROP) {
+ aListOfMap[viewIndex].insert( ISOS_PROP, val);
+
+ } else if(paramNameStr == COLOR_PROP) {
+ QStringList rgb = val.split(DIGIT_SEPARATOR);
+ if(rgb.count() == 3) {
+ QColor c(int(rgb[0].toDouble()*255), int(rgb[1].toDouble()*255), int(rgb[2].toDouble()*255));
+ aListOfMap[viewIndex].insert( COLOR_PROP, c);
+ }
+ } else if(paramNameStr == VECTOR_MODE_PROP) {
+ aListOfMap[viewIndex].insert( VECTOR_MODE_PROP, val.toInt());
+
+ } else if(paramNameStr == DEFLECTION_COEFF_PROP) {
+ aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble());
+ } else if(paramNameStr == MARKER_TYPE_PROP) {
+ aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val);
+ } else if(paramNameStr == MATERIAL_PROP) {
+ aListOfMap[viewIndex].insert( MATERIAL_PROP, val);
+ } else if(paramNameStr == EDGE_WIDTH_PROP) {
+ aListOfMap[viewIndex].insert( EDGE_WIDTH_PROP , val);
+ } else if(paramNameStr == ISOS_WIDTH_PROP) {
+ aListOfMap[viewIndex].insert( ISOS_WIDTH_PROP , val);
+ }
+
+
+
+ } // 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(VISIBILITY_PROP) == 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 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;
+}
+