Salome HOME
Update French translations
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
index eb4aa6d772f0bf039af3e7b294126c7707d9b4f5..685c6551bdc00cbd0fa2a27fdcab700c435f91c2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -426,6 +426,8 @@ void GeometryGUI::OnGUIEvent( int id )
   case GEOMOp::OpMaterialProperties: // POPUP MENU - MATERIAL PROPERTIES
   case GEOMOp::OpEdgeWidth:          // POPUP MENU - LINE WIDTH - EDGE WIDTH
   case GEOMOp::OpIsosWidth:          // POPUP MENU - LINE WIDTH - ISOS WIDTH
+  case GEOMOp::OpBringToFront:       // POPUP MENU - BRING TO FRONT
+  case GEOMOp::OpClsBringToFront:    //
     libName = "GEOMToolsGUI";
     break;
   case GEOMOp::OpDisplayMode:        // MENU VIEW - WIREFRAME/SHADING
@@ -589,10 +591,7 @@ void GeometryGUI::OnGUIEvent( int id )
       if ( pref ) {
        Material_ResourceMgr aMatResMgr;
        QStringList aPerfMatNames = aMatResMgr.getPreferenceMaterialsNames();
-       setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_FRONT_MATERIAL" ), true )->id(),
-                              "strings",
-                              aPerfMatNames );
-       setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_BACK_MATERIAL" ), true )->id(),
+       setPreferenceProperty( pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true )->id(),
                               "strings",
                               aPerfMatNames );
       }
@@ -844,6 +843,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   createGeomAction( GEOMOp::OpSelectCompound,   "COMPOUND_SEL_ONLY", "",  0, true );
   createGeomAction( GEOMOp::OpSelectAll,        "ALL_SEL_ONLY", "",  0, true );
   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
+  createGeomAction( GEOMOp::OpBringToFront,     "BRING_TO_FRONT", "", 0, true );
+  createGeomAction( GEOMOp::OpClsBringToFront,  "CLS_BRING_TO_FRONT" );
   createGeomAction( GEOMOp::OpHide,             "ERASE" );
 
   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
@@ -906,6 +907,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   createMenu( GEOMOp::OpArc,     basicId, -1 );
   createMenu( GEOMOp::OpCurve,   basicId, -1 );
   createMenu( separator(),       basicId, -1 );
+  createMenu( GEOMOp::Op2dSketcher, basicId, -1 );
+  createMenu( GEOMOp::Op3dSketcher, basicId, -1 );
   createMenu( GEOMOp::OpVector,  basicId, -1 );
   createMenu( GEOMOp::OpPlane,   basicId, -1 );
   createMenu( GEOMOp::OpLCS,     basicId, -1 );
@@ -919,6 +922,7 @@ void GeometryGUI::initialize( CAM_Application* app )
   createMenu( GEOMOp::OpCone,      primId, -1 );
   createMenu( GEOMOp::OpRectangle, primId, -1 );
   createMenu( GEOMOp::OpDisk,      primId, -1 );
+  createMenu( GEOMOp::OpPipeTShape,primId, -1 );
 
   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
   createMenu( GEOMOp::OpPrism,      genId, -1 );
@@ -926,8 +930,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   createMenu( GEOMOp::OpFilling,    genId, -1 );
   createMenu( GEOMOp::OpPipe,       genId, -1 );
 
-  int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
-  createMenu( GEOMOp::OpPipeTShape, advId, -1 );
+//   int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
+//   createMenu( GEOMOp::OpPipeTShape, advId, -1 );
 //   createMenu( GEOMOp::OpPipeTShapeGroups, advId, -1 );
   //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
 
@@ -945,11 +949,6 @@ void GeometryGUI::initialize( CAM_Application* app )
 
   createMenu( separator(),          newEntId, -1 );
 
-  createMenu( GEOMOp::Op2dSketcher, newEntId, -1 );
-  createMenu( GEOMOp::Op3dSketcher, newEntId, -1 );
-
-  createMenu( separator(),          newEntId, -1 );
-
   createMenu( GEOMOp::OpExplode,    newEntId, -1 );
 
   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
@@ -1218,6 +1217,17 @@ void GeometryGUI::initialize( CAM_Application* app )
   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
   mgr->insert( separator(), -1, -1 );     // -----------
+
+#if OCC_VERSION_LARGE > 0x06050200
+  //QString bringRule = clientOCCorOB + " and ($component={'GEOM'}) and (selcount>0) and isOCC=true and topLevel=false";
+  QString bringRule = clientOCCorOB + " and ($component={'GEOM'}) and (selcount>0) and isOCC=true";
+  mgr->insert( action(GEOMOp::OpBringToFront ), -1, -1 ); // bring to front
+  mgr->setRule(action(GEOMOp::OpBringToFront), bringRule, QtxPopupMgr::VisibleRule );
+  mgr->setRule(action(GEOMOp::OpBringToFront), "topLevel=true", QtxPopupMgr::ToggleRule );
+  mgr->insert( action(GEOMOp::OpClsBringToFront ), -1, -1 ); // clear bring to front
+  mgr->setRule( action(GEOMOp::OpClsBringToFront ), clientOCC, QtxPopupMgr::VisibleRule );  
+#endif
+  mgr->insert( separator(), -1, -1 );     // -----------
   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
@@ -1237,7 +1247,7 @@ void GeometryGUI::initialize( CAM_Application* app )
   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
   mgr->insert( separator(), -1, -1 );     // -----------
   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
-  mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
+  mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})" + "and isPhysicalMaterial=false", QtxPopupMgr::VisibleRule );
   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
@@ -1310,7 +1320,6 @@ void GeometryGUI::initialize( CAM_Application* app )
   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
-  mgr->insert( separator(), -1, -1 );
 
   mgr->insert( separator(), -1, -1 );     // -----------
   mgr->insert( action(  GEOMOp::OpUnpublishObject ), -1, -1 ); // Unpublish object
@@ -1695,20 +1704,22 @@ void GeometryGUI::createPreferences()
   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
                  LightApp_Preferences::Color, "Geometry", "isos_color" );
 
+  addPreference( tr( "PREF_TOPLEVEL_COLOR" ), genGroup,
+                 LightApp_Preferences::Color, "Geometry", "toplevel_color" );
+
+  addPreference( "", genGroup, LightApp_Preferences::Space );
+
+
   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" );
 
-  int front_material = addPreference( tr( "PREF_FRONT_MATERIAL" ), genGroup,
+  int material = addPreference( tr( "PREF_MATERIAL" ), genGroup,
                                      LightApp_Preferences::Selector,
-                                     "Geometry", "front_material" );
+                                     "Geometry", "material" );
   
-  int back_material = addPreference( tr( "PREF_BACK_MATERIAL" ), genGroup,
-                                    LightApp_Preferences::Selector,
-                                    "Geometry", "back_material" );
-
   const int nb = 4;
   int wd[nb];
   int iter=0;
@@ -1798,8 +1809,7 @@ void GeometryGUI::createPreferences()
   // Set property for default material
   Material_ResourceMgr aMatResMgr;
   QStringList aPrefMatNames = aMatResMgr.getPreferenceMaterialsNames();
-  setPreferenceProperty( front_material, "strings", aPrefMatNames );
-  setPreferenceProperty( back_material, "strings", aPrefMatNames );
+  setPreferenceProperty( material, "strings", aPrefMatNames );
 
   // Set property vertex marker type
   QList<QVariant> aMarkerTypeIndicesList;
@@ -1966,6 +1976,13 @@ void GeometryGUI::storeVisualParameters (int savePoint)
             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)) {
@@ -1989,17 +2006,11 @@ void GeometryGUI::storeVisualParameters (int savePoint)
           ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data());
         }
 
-       if(aProps.contains(FRONT_MATERIAL_PROP)) {
-          param = occParam + FRONT_MATERIAL_PROP;
-          ip->setParameter(entry, param, aProps.value(FRONT_MATERIAL_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(BACK_MATERIAL_PROP)) {
-          param = occParam + BACK_MATERIAL_PROP;
-          ip->setParameter(entry, param, aProps.value(BACK_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());                              
@@ -2094,9 +2105,12 @@ void GeometryGUI::restoreVisualParameters (int savePoint)
       } 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 == 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());
 
@@ -2116,10 +2130,8 @@ void GeometryGUI::restoreVisualParameters (int savePoint)
         aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble());
       }  else if(paramNameStr == MARKER_TYPE_PROP) {
         aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val);
-      } else if(paramNameStr == FRONT_MATERIAL_PROP) {
-        aListOfMap[viewIndex].insert( FRONT_MATERIAL_PROP, val);
-      } else if(paramNameStr == BACK_MATERIAL_PROP) {
-        aListOfMap[viewIndex].insert( BACK_MATERIAL_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) {
@@ -2181,6 +2193,34 @@ void GeometryGUI::onViewAboutToShow()
   }
 }
 
+/*!
+  \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
@@ -2188,24 +2228,26 @@ void GeometryGUI::onViewAboutToShow()
   \brief Return \c true if rename operation finished successfully, \c false otherwise.
 */
 bool GeometryGUI::renameObject( const QString& entry, const QString& name) {
-
-  bool appRes = SalomeApp_Module::renameObject(entry,name);
-  if( !appRes )
-    return false;
-
+  
   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 ) {
@@ -2222,3 +2264,4 @@ bool GeometryGUI::renameObject( const QString& entry, const QString& name) {
   }
   return result;
 }
+