Salome HOME
MPV: Merge V1_2d
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI.cxx
index ecc765b86fbebba0cee52d457fe705c6561724ee..5f57e853113e8b748b6f3e052cb562287d71938b 100644 (file)
@@ -1,11 +1,31 @@
-using namespace std;
-//  File      : SUPERVGUI.cxx
-//  Created   : 31 octobre 2001
-//  Author    : Francis KLOSS
-//  Project   : SALOME
-//  Module    : SUPERVGUI
-//  Copyright : CEA
+//  SUPERV SUPERVGUI : GUI for Supervisor component
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SUPERVGUI.cxx
+//  Author : Francis KLOSS
+//  Module : SUPERV
 
+using namespace std;
 #include "SUPERVGUI.h"
 
 #include "QAD_Resource.h"
@@ -33,11 +53,10 @@ SUPERVGUI Supervision;
 
 
 SUPERVGUI::SUPERVGUI(): QObject(),
-    desktop(0),
-    study(0),
-    engine(0),
-    browser(0)
-                       //info(0)
+                       desktop(0),
+                       study(0),
+                       browser(0)
+  //info(0)
 {
     Trace("SUPERVGUI::SUPERVGUI")
     if (factory==0) {
@@ -52,8 +71,9 @@ SUPERVGUI::~SUPERVGUI() {
     Trace("SUPERVGUI::~SUPERVGUI")
     if (factory==1) {
         factory = 0;
+       //if (!engine->_is_nil()) CORBA::release(engine);         
         //info->close();
-        browser->close();
+        if (browser) browser->close();
         MESSAGE("SUPERVGUI Info : factory destroy");
     } else {
         MESSAGE("SUPERVGUI Error : another call to factory destructor");
@@ -105,8 +125,8 @@ void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
         return;
     };
 
-    engine  = new SUPERV::SuperG_var;
-    *engine = aSuperVisionComponent;
+    //    engine  = new SUPERV::SuperG_var;
+    engine = aSuperVisionComponent;
 }
 /*
 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
@@ -216,7 +236,7 @@ void SUPERVGUI::importDataflow() {
        return;
     }
 
-    SUPERV_Graph aGraph = (*Supervision.getEngine())->GraphE(f);
+    SUPERV_Graph aGraph = engine->GraphE(f);
     //QFileInfo aFile(f);
     //aGraph->SetName(aFile.baseName());
     if (SUPERV_isNull(aGraph)) {
@@ -254,7 +274,7 @@ void SUPERVGUI::displayDataflow() {
                                 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
          return;
       }
-      aDataFlow = (*Supervision.getEngine())->getGraph(ior);
+      aDataFlow = engine->getGraph(ior);
       if (SUPERV_isNull(aDataFlow)) {
        QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
        return;
@@ -345,7 +365,7 @@ void SUPERVGUI::modifyDataflow() {
        return;
       }
       
-      SUPERV_Graph aGraph = (*Supervision.getEngine())->Graph(f);
+      SUPERV_Graph aGraph = engine->Graph(f);
       //QFile aFile(f);
       //aGraph->SetName(aFile.name());
       if (SUPERV_isNull(aGraph)) {
@@ -435,20 +455,35 @@ void SUPERVGUI::customPopup(QPopupMenu* popup) {
     SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
     if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
 
-    Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
+    if (Sel->IObjectCount() == 1) {
+      Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
 
-    // insert SUPERV-specific popup items here
+      // insert SUPERV-specific popup items here
 
-    bool isDataflow, ownObj;
-    whatIsSelected(anIObj, ownObj, isDataflow);
-    
-    if (isDataflow) {
-      popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
-      popup->insertItem("Display", this, SLOT(displayDataflow()));
-      popup->insertSeparator();
+      bool isDataflow, ownObj;
+      whatIsSelected(anIObj, ownObj, isDataflow);
+      
+      if (isDataflow) {
+       popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
+       popup->insertItem("Display", this, SLOT(displayDataflow()));
+       popup->insertSeparator();
+      }
+      if (ownObj)
+       popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
+    }
+    if (Sel->IObjectCount() > 1) {
+      int aIObjCount = 0;
+      SALOME_ListIteratorOfListIO It_forCheckOwner(Sel->StoredIObjects());
+      for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
+       Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
+       bool aIsOwner, aIsDataflow;
+       whatIsSelected(anIObj, aIsOwner, aIsDataflow);
+       
+       if (aIsOwner) aIObjCount++;
+      }
+      if (aIObjCount == Sel->IObjectCount())  //all selected objects belong to Supervision
+       popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
     }
-    if (ownObj)
-      popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
 }
 
  
@@ -474,12 +509,12 @@ void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, b
       if (comp->FindAttribute(anAttr, "AttributeName")) {
        aName = SALOMEDS::AttributeName::_narrow(anAttr);
        QString compName(aName->Value());
-       //      if (compName.compare(STUDY_SUPERVISION) == 0) {
-       if (compName.compare( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) == 0) {
+       //if (compName.compare(STUDY_SUPERVISION) == 0) {
+       if (compName.compare(QAD_Application::getDesktop()->getComponentUserName("SUPERV")) == 0) {
          SALOMEDS::GenericAttribute_var anAttr;
          if (obj->FindAttribute(anAttr, "AttributeIOR")) {
            SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-           SUPERV_Graph aDataFlow = (*Supervision.getEngine())->getGraph(anIOR->Value());
+           SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value());
            if (!SUPERV_isNull(aDataFlow)) 
              theIsDataflow = true;
          }
@@ -496,43 +531,44 @@ void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, b
 void SUPERVGUI::deleteObject() {
   SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
   if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
-  
-  Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
-  bool aIsOwner, aIsDataflow;
-  whatIsSelected(anIObj, aIsOwner, aIsDataflow);
-
-  if (!aIsOwner) return;
-
+   
   if (QMessageBox::warning(QAD_Application::getDesktop(),
                           tr("WARNING"),
                           tr("MSG_ASK_DELETE"),
                           QMessageBox::No,
                           QMessageBox::Yes) == QMessageBox::No)
     return;
-  
-  SALOMEDS::Study_var aStudy = study->getStudyDocument();
-  SALOMEDS::SObject_var  aObj = aStudy->FindObjectID( anIObj->getEntry() );
-  if (!aObj->_is_nil()) {
-    if (aIsDataflow) {
-      SALOMEDS::GenericAttribute_var anAttr;
-      if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
-       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-       QString ior = anIOR->Value();
-       
-       SUPERVGUI_Main* aMain;
-       for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
-         if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
-           aMain->setAsFromStudy(false);
-           break;
+   
+  SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
+  for(;It.More();It.Next()) {
+    Handle(SALOME_InteractiveObject) anIObj = It.Value();
+    bool aIsOwner, aIsDataflow;
+    whatIsSelected(anIObj, aIsOwner, aIsDataflow);
+    
+    SALOMEDS::Study_var aStudy = study->getStudyDocument();
+    SALOMEDS::SObject_var  aObj = aStudy->FindObjectID( anIObj->getEntry() );
+    if (!aObj->_is_nil()) {
+      if (aIsDataflow) {
+       SALOMEDS::GenericAttribute_var anAttr;
+       if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
+         SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
+         QString ior = anIOR->Value();
+           
+         SUPERVGUI_Main* aMain;
+         for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
+           if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
+             aMain->setAsFromStudy(false);
+             break;
+           }
          }
-       }
+        }
       }
+      QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
+      SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
+      op->start();
+      aBuilder->RemoveObjectWithChildren(aObj);
+      op->finish();
     }
-    QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
-    SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
-    op->start();
-    aBuilder->RemoveObjectWithChildren(aObj);
-    op->finish();
   }
   Sel->ClearIObjects() ; 
 }
@@ -635,3 +671,7 @@ extern "C" int supportedViewType()
 {
   return (int)VIEW_GRAPHSUPERV;
 }
+
+extern "C" void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
+{
+}