+void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
+{
+ SalomeApp_Module::contextMenuPopup(client, menu, title);
+
+ SALOME_ListIO lst;
+ getApp()->selectionMgr()->selectedObjects(lst);
+ if (lst.Extent() < 1)
+ return;
+
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
+ _PTR(Study) study = appStudy->studyDS();
+
+ bool isImported = true;
+ SALOME_ListIteratorOfListIO anIt (lst);
+ for (; anIt.More() && isImported; anIt.Next()) {
+ Handle(SALOME_InteractiveObject) io = anIt.Value();
+ _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
+ if (aSObj) {
+ if (lst.Extent() == 1) {
+ // Set context menu title
+ if (client == "OCCViewer" || client == "VTKViewer")
+ title = QString(aSObj->GetName().c_str());
+ }
+
+ CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
+ GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
+ if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
+ isImported = false;
+ } else {
+ isImported = false;
+ }
+ }
+
+ if (isImported) {
+ menu->addAction(action(GEOMOp::OpReimport)); // Reload imported shape
+ }
+}
+
+void GeometryGUI::createPreferences()
+{
+ int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
+
+ int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
+ setPreferenceProperty( genGroup, "columns", 2 );
+
+ int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
+ LightApp_Preferences::Selector,
+ "Geometry", "display_mode" );
+
+ addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
+ LightApp_Preferences::Color, "Geometry", "shading_color" );
+
+ addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
+ LightApp_Preferences::Color, "Geometry", "wireframe_color" );
+
+ addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
+ LightApp_Preferences::Color, "Geometry", "free_bound_color" );
+
+ addPreference( tr( "PREF_LINE_COLOR"), genGroup,
+ LightApp_Preferences::Color, "Geometry", "line_color" );
+
+ addPreference( tr( "PREF_POINT_COLOR"), genGroup,
+ LightApp_Preferences::Color, "Geometry", "point_color" );
+
+ addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
+ LightApp_Preferences::Color, "Geometry", "isos_color" );
+
+ int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
+
+ int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
+ LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
+
+ // Quantities with individual precision settings
+ int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
+ setPreferenceProperty( precGroup, "columns", 2 );
+
+ const int nbQuantities = 8;
+ int prec[nbQuantities], ii = 0;
+ prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
+ prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
+ prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
+ prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
+ prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
+ prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
+ prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
+ prec[ii ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
+ LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
+
+ // Set property for precision value for spinboxes
+ for ( ii = 0; ii < nbQuantities; ii++ ){
+ setPreferenceProperty( prec[ii], "min", -14 );
+ setPreferenceProperty( prec[ii], "max", 14 );
+ setPreferenceProperty( prec[ii], "precision", 2 );
+ }
+
+ int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
+ setPreferenceProperty( VertexGroup, "columns", 2 );
+
+ int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
+ LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
+
+ int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
+ LightApp_Preferences::Selector, "Geometry", "marker_scale" );
+
+ // Set property for default display mode
+ QStringList aModesList;
+ aModesList.append( tr("MEN_WIREFRAME") );
+ aModesList.append( tr("MEN_SHADING") );
+
+ QList<QVariant> anIndexesList;
+ anIndexesList.append(0);
+ anIndexesList.append(1);
+
+ setPreferenceProperty( dispmode, "strings", aModesList );
+ setPreferenceProperty( dispmode, "indexes", anIndexesList );
+
+ // Set property for step value for spinboxes
+ setPreferenceProperty( step, "min", 1 );
+ setPreferenceProperty( step, "max", 10000 );
+ setPreferenceProperty( step, "precision", 3 );
+
+ // Set property for deflection value for spinboxes
+ setPreferenceProperty( defl, "min", DEFLECTION_MIN );
+ setPreferenceProperty( defl, "max", 1.0 );
+ setPreferenceProperty( defl, "step", 1.0e-04 );
+ setPreferenceProperty( defl, "precision", 6 );
+
+ // Set property vertex marker type
+ QList<QVariant> aMarkerTypeIndicesList;
+ QList<QVariant> aMarkerTypeIconsList;
+
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
+ QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
+ QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
+ aMarkerTypeIndicesList << (i-1);
+ aMarkerTypeIconsList << pixmap;
+ }
+
+ setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
+ setPreferenceProperty( typeOfMarker, "icons", aMarkerTypeIconsList );
+
+ // Set property for vertex marker scale
+ QList<QVariant> aMarkerScaleIndicesList;
+ QStringList aMarkerScaleValuesList;
+
+ for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
+ aMarkerScaleIndicesList << iii;
+ aMarkerScaleValuesList << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
+ }
+
+ setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
+ setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
+
+ int originGroup = addPreference( tr( "PREF_GROUP_ORIGIN_AND_BASE_VECTORS" ), tabId );
+ setPreferenceProperty( originGroup, "columns", 2 );
+
+ int baseVectorsLength = addPreference( tr( "PREF_BASE_VECTORS_LENGTH" ), originGroup,
+ LightApp_Preferences::DblSpin, "Geometry", "base_vectors_length" );
+ setPreferenceProperty( baseVectorsLength, "min", 0.01 );
+ setPreferenceProperty( baseVectorsLength, "max", 1000 );
+
+ addPreference( tr( "PREF_AUTO_CREATE" ), originGroup,
+ LightApp_Preferences::Bool, "Geometry", "auto_create_base_objects" );
+
+}
+
+void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
+{
+ 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);
+ }
+ }
+}
+
+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 attribue(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 )
+ 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;
+
+ param = occParam + VISIBILITY_PROP;
+ ip->setParameter(entry, param, aProps.value(VISIBILITY_PROP).toInt() == 1 ? "On" : "Off");
+
+ param = occParam + DISPLAY_MODE_PROP;
+
+ ip->setParameter(entry, param, QString::number(aProps.value(DISPLAY_MODE_PROP).toInt()).toLatin1().data());
+
+ 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()) {
+ param = occParam + OPACITY_PROP;
+ ip->setParameter(entry, param, QString::number(1. - aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
+ } else if (vType == SOCC_Viewer::Type()) {
+ param = occParam + TRANSPARENCY_PROP;
+ ip->setParameter(entry, param, QString::number(aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
+ }
+
+ param = occParam + ISOS_PROP;
+ ip->setParameter(entry, param, aProps.value(ISOS_PROP).toString().toLatin1().data());
+
+ param = occParam + VECTOR_MODE_PROP;
+ ip->setParameter(entry, param, QString::number(aProps.value(VECTOR_MODE_PROP).toInt()).toLatin1().data());
+
+ param = occParam + DEFLECTION_COEFF_PROP;
+ ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data());
+
+ 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());
+ }
+
+ } // 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 attribue(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 == 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);
+ }
+
+ } // for names/parameters iterator
+
+ QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
+
+ for (int index = 0 ; index < aListOfMap.count(); index++) {
+
+ appStudy->setObjectPropMap(index, entry, aListOfMap[index]);
+
+ QColor c = aListOfMap[index].value(COLOR_PROP).value<QColor>();
+ //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->getCustomData("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);
+ }
+}