Salome HOME
SALOME PAL V1_4_1
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SUPERVGUI.cxx
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 using namespace std;
29 #include "SUPERVGUI.h"
30
31 #include "QAD_Resource.h"
32 #include "QAD_FileDlg.h"
33 #include "QAD_Application.h"
34 #include "QAD_StudyFrame.h"
35 #include "QAD_RightFrame.h"
36 #include "QAD_LeftFrame.h"
37 #include "QAD_ViewFrame.h"
38 #include "QAD_ObjectBrowser.h"
39 #include "QAD_ObjectBrowserItem.h"
40 #include "SALOME_Selection.h"
41 #include "SALOMEGUI_NameDlg.h"            
42 #include "Utils_ORB_INIT.hxx"
43 #include "SALOME_ListIteratorOfListIO.hxx"
44 #include "SALOME_InteractiveObject.hxx"
45 #include <qapplication.h>
46 #include "SALOMEGUI_ImportOperation.h"
47
48 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
49
50
51 int SUPERVGUI::factory = 0;
52 SUPERVGUI Supervision;
53
54
55 SUPERVGUI::SUPERVGUI(): QObject(),
56                         desktop(0),
57                         study(0),
58                         browser(0)
59   //info(0)
60 {
61     Trace("SUPERVGUI::SUPERVGUI")
62     if (factory==0) {
63         factory = 1;
64         MESSAGE("SUPERVGUI Info : factory build");
65     } else {
66         MESSAGE("SUPERVGUI Error : another call to factory constructor");
67     };
68 }
69
70 SUPERVGUI::~SUPERVGUI() {
71     Trace("SUPERVGUI::~SUPERVGUI")
72     if (factory==1) {
73         factory = 0;
74         //if (!engine->_is_nil()) CORBA::release(engine);         
75         //info->close();
76         if (browser) browser->close();
77         MESSAGE("SUPERVGUI Info : factory destroy");
78     } else {
79         MESSAGE("SUPERVGUI Error : another call to factory destructor");
80     };
81 }
82
83 void SUPERVGUI::init(QAD_Desktop* parent) {
84     Trace("SUPERVGUI::init")
85     if (desktop==0) {
86         desktop = parent;
87         study = desktop->getActiveStudy();
88         SALOME_NamingService* namingService = desktop->getNameService();
89         loadEngine(namingService);
90         browser = new SUPERVGUI_Service(namingService);
91         //info    = new SUPERVGUI_Information();
92         cursor  = desktop->cursor();
93         connect(desktop->getMainFrame(), SIGNAL(windowActivated(QWidget*)), this, SLOT(setMain(QWidget*)));
94
95         int anId = 300;
96         parent->menuBar()->changeItem(anId,parent->getComponentUserName("SUPERV"));
97         
98     };
99 }
100
101
102 QAD_StudyFrame* SUPERVGUI::createGraph() {
103   QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(),
104                                                    VIEW_GRAPHSUPERV, false);
105   if (aStudyFrame) {
106     connect(aStudyFrame, 
107             SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)), 
108             &Supervision, 
109             SLOT(onGraphClosed(QAD_StudyFrame*)));
110   }
111   return aStudyFrame;
112 }
113
114
115
116 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
117     Trace("SUPERVGUI::loadEngine")
118     SALOME_LifeCycleCORBA LCC(namingService);
119     Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
120     if (CORBA::is_nil(objComponent)) {
121         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
122         return;
123     };
124
125     SUPERV::SuperG_var aSuperVisionComponent;
126     aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
127     if (CORBA::is_nil(aSuperVisionComponent)) {
128         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
129         return;
130     };
131
132     //    engine  = new SUPERV::SuperG_var;
133     engine = aSuperVisionComponent;
134 }
135 /*
136 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
137     Trace("SUPERVGUI::information")
138     return(info->run(node, isReadOnly));
139 }
140 */
141 void SUPERVGUI::putInfo(const char* mess) {
142     Trace("SUPERVGUI::putInfo")
143     desktop->putInfo(mess);
144 }
145
146 QAD_Desktop* SUPERVGUI::getDesktop() {
147     Trace("SUPERVGUI::getDesktop")
148     return(desktop);
149 }
150
151 SUPERV_Engine SUPERVGUI::getEngine() {
152     Trace("SUPERVGUI::getEngine")
153     return(engine);
154 }
155
156 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
157     Trace("SUPERVGUI::getBrowser")
158     return(browser);
159 }
160
161 QCursor SUPERVGUI::getCursor() {
162     Trace("SUPERVGUI::getCursor")
163     return(cursor);
164 }
165
166 SUPERVGUI_Main* SUPERVGUI::getMain() {
167     Trace("SUPERVGUI::getMain")
168     return main;
169 }
170
171
172 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
173   theGraph->setHashCode(theName);
174   myGraphList.append(theGraph);
175 }
176
177
178 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
179   SUPERVGUI_Main* aMain;
180   for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
181     if (aMain == theGraph)
182       myGraphList.remove(aMain);
183   }
184 }
185
186
187 bool SUPERVGUI::isContains(QAD_Study* theStudy, const QString theKey) {
188   SUPERVGUI_Main* aMain;
189   for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
190     if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
191       return true;
192   }
193   return false;
194 }
195
196
197 void SUPERVGUI::onGraphClosed(QAD_StudyFrame* theStudyFrame) {
198   QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
199   if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
200     disconnect(theStudyFrame, 0 , this, 0);
201     SUPERVGraph_View* view = supervFrame->getViewWidget();
202     SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
203     if (aGraph) {
204       unregisterGraph(aGraph);
205     }
206   }
207 }
208
209 void SUPERVGUI::setMain(QWidget* w) {
210   main = 0;
211   QAD_StudyFrame* aStudyFrame = dynamic_cast<QAD_StudyFrame*>(w);
212   if (!aStudyFrame) return;
213
214   study = aStudyFrame->getStudy();
215   if (!study) return;
216
217   QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame();
218   if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
219     SUPERVGraph_View* view = supervFrame->getViewWidget();
220     if (view)
221       main = dynamic_cast<SUPERVGUI_Main*>(view);
222   }
223   Trace("SUPERVGUI::setMain - main: "<<main);
224 }
225
226
227 void SUPERVGUI::importDataflow() {
228   Trace("SUPERVGUI::importDataflow");
229   QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
230                                        "",
231                                        "*.xml",
232                                        tr("MSG_IMPORT"),
233                                        true);
234   
235   if (!f.isEmpty()) {
236     if (isContains(study, f)) {
237       if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
238                                tr("MSG_GRAPH_DISPLAYED").arg(f), 
239                                QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
240         return;
241     }
242
243     SUPERV_Graph aGraph = engine->GraphE(f);
244     //QFileInfo aFile(f);
245     //aGraph->SetName(aFile.baseName());
246     if (SUPERV_isNull(aGraph)) {
247       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
248       return;
249     }
250
251     QAD_StudyFrame* aStudyFrame = createGraph();
252     SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
253       (aStudyFrame->getRightFrame()->getViewFrame());
254     if(aViewFrame) {
255       main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
256       registerGraph(f, main);
257       study->showFrame(aStudyFrame);
258     }   
259   }
260 }
261
262 void SUPERVGUI::displayDataflow() {
263     Trace("SUPERVGUI::displayDataflow");
264     QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
265     SUPERV_Graph aDataFlow;
266     QString aIORName;
267
268     QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(aBrowser->getListView()->currentItem());
269     SALOMEDS::SObject_var aObj = desktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
270     SALOMEDS::GenericAttribute_var anAttr;
271     if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
272       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
273       Standard_CString ior = anIOR->Value();
274       aIORName = ior;
275       if (isContains(study, aIORName)) {
276         if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
277                                  tr("MSG_GRAPH_DISPLAYED").arg(""), 
278                                  QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
279           return;
280       }
281       aDataFlow = engine->getGraph(ior);
282       if (SUPERV_isNull(aDataFlow)) {
283         QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
284         return;
285       }
286     }
287     QAD_StudyFrame* aStudyFrame = createGraph();
288     SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
289       (aStudyFrame->getRightFrame()->getViewFrame());
290     if(aViewFrame) {
291       main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow);
292       main->setAsFromStudy(true);
293       registerGraph(aIORName, main);
294       study->showFrame(aStudyFrame);
295     }
296 }
297
298
299 void SUPERVGUI::renameDataflow() {
300   SALOME_Selection* Sel = SALOME_Selection::Selection( study->getSelection() );
301   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
302   for ( ; It.More(); It.Next() ) {
303     Handle(SALOME_InteractiveObject) IObject = It.Value();
304     
305     SALOMEDS::Study_var aStudy = study->getStudyDocument();
306     SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
307     SALOMEDS::GenericAttribute_var anAttr;
308     SALOMEDS::AttributeName_var    aName;
309     if ( !obj->_is_nil() ) {
310       if (obj->FindAttribute(anAttr, "AttributeName")) {
311         aName = SALOMEDS::AttributeName::_narrow(anAttr);
312         QString nm = QString( aName->Value() );
313         bool ok = FALSE;
314         nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm );
315         if ( !nm.isEmpty() ) {
316           QApplication::setOverrideCursor( Qt::waitCursor );
317           study->renameIObject( IObject, nm );
318           QApplication::restoreOverrideCursor();
319         }
320       }
321     }
322   }
323 }
324
325
326 void SUPERVGUI::exportDataflow() {
327     Trace("SUPERVGUI::exportDataflow")
328     if (main==0) {
329         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
330     } else {
331       QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
332                                            "",
333                                            "*.xml",
334                                            tr("TTL_EXPORT_DATAFLOW"),
335                                            false);
336       if (!f.isEmpty()) {
337         if (main->exportDataflow(f)) {
338           unregisterGraph(main);
339           registerGraph(f, main);
340         }
341       }
342     }
343 }
344
345 void SUPERVGUI::newDataflow() {
346     Trace("SUPERVGUI::editDataflow");
347     QAD_StudyFrame* aStudyFrame = createGraph();
348     SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
349       (aStudyFrame->getRightFrame()->getViewFrame());
350     if(aViewFrame){
351       main = new SUPERVGUI_Main(aViewFrame, desktop, false);
352       main->addNode();
353       study->showFrame(aStudyFrame);
354     }
355 }
356
357 void SUPERVGUI::modifyDataflow() {
358     Trace("SUPERVGUI::modifyDataflow")
359     QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
360                                          "",
361                                          "*.xml",
362                                          tr("Modify Dataflow"),
363                                          true);
364     if (!f.isEmpty()){
365       if (isContains(study, f)) {
366       if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
367                                tr("MSG_GRAPH_DISPLAYED").arg(f), 
368                                QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
369         return;
370       }
371       
372       SUPERV_Graph aGraph = engine->Graph(f);
373       //QFile aFile(f);
374       //aGraph->SetName(aFile.name());
375       if (SUPERV_isNull(aGraph)) {
376         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
377         return;
378       }
379
380       QAD_StudyFrame* aStudyFrame = createGraph();
381       SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
382         (aStudyFrame->getRightFrame()->getViewFrame());
383       if(aViewFrame) {
384         main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
385         registerGraph(f, main);
386         study->showFrame(aStudyFrame);
387       }
388     }
389 }
390
391 void SUPERVGUI::reloadDataflow() {
392     Trace("SUPERVGUI::reloadDataflow")
393     if (main==0) {
394         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
395     } else {
396         main->sync();
397     };
398 }
399
400 void SUPERVGUI::runDataflow() {
401     Trace("SUPERVGUI::runDataflow")
402     if (main==0) {
403         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
404     } else {
405         main->run();
406     };
407 }
408
409 void SUPERVGUI::stepByStep() {
410     Trace("SUPERVGUI::stepByStep")
411     if (main==0) {
412         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
413     } else {
414         main->startExecute();
415     }
416 }
417
418 void SUPERVGUI::killDataflow() {
419     Trace("SUPERVGUI::killDataflow")
420     if (main==0) {
421         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
422     } else {
423         main->kill();
424     };
425 }
426
427 void SUPERVGUI::suspendResumeDataflow() {
428     Trace("SUPERVGUI::suspendResumeDataflow")
429     if (main==0) {
430         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
431     } else {
432         main->suspendResume();
433     };
434 }
435
436 void SUPERVGUI::showComponents() {
437   Trace("SUPERVGUI::showComponents");
438   if (main==0) {
439     QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
440   } else {
441     if (main->isEditable())
442       main->addNode();
443     else
444       QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
445   }
446 }
447
448 void SUPERVGUI::customPopup(QPopupMenu* popup) {
449   Trace("SUPERVGUI::customPopup");
450   if(popup->count() > 3) {
451     // Temporary code: is to be deleted soon
452     popup->removeItem(QAD_Display_Popup_ID);
453     popup->removeItem(QAD_DisplayOnly_Popup_ID);
454     popup->removeItem(QAD_Erase_Popup_ID);
455     int id = popup->idAt(popup->count() - 1);
456     if (id < 0 && id != -1) popup->removeItem(id); // separator
457     // Temporary code end
458   }
459     SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
460     if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
461
462     if (Sel->IObjectCount() == 1) {
463       Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
464
465       // insert SUPERV-specific popup items here
466
467       bool isDataflow, ownObj;
468       whatIsSelected(anIObj, ownObj, isDataflow);
469       
470       if (isDataflow) {
471         popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
472         popup->insertItem("Display", this, SLOT(displayDataflow()));
473         popup->insertSeparator();
474       }
475       if (ownObj)
476         popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
477     }
478     if (Sel->IObjectCount() > 1) {
479       int aIObjCount = 0;
480       SALOME_ListIteratorOfListIO It_forCheckOwner(Sel->StoredIObjects());
481       for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
482         Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
483         bool aIsOwner, aIsDataflow;
484         whatIsSelected(anIObj, aIsOwner, aIsDataflow);
485         
486         if (aIsOwner) aIObjCount++;
487       }
488       if (aIObjCount == Sel->IObjectCount())  //all selected objects belong to Supervision
489         popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
490     }
491 }
492
493  
494
495 /** Returns:
496     theIsOwner = true if Selected object belongs to Suipervision.
497     theIsDataflow = true if Selected object is Dataflow
498 */
499 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
500   theIsOwner = false;
501   theIsDataflow = false;
502
503   if (theObj.IsNull()) return;
504   
505   SALOMEDS::Study_var aStudy = study->getStudyDocument();
506   SALOMEDS::SObject_var  obj = aStudy->FindObjectID( theObj->getEntry() );
507
508   if ( !obj->_is_nil() ) {
509     SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
510     if ( !comp->_is_nil() ) {
511       SALOMEDS::GenericAttribute_var anAttr;
512       SALOMEDS::AttributeName_var    aName;
513       if (comp->FindAttribute(anAttr, "AttributeName")) {
514         aName = SALOMEDS::AttributeName::_narrow(anAttr);
515         QString compName(aName->Value());
516         //if (compName.compare(STUDY_SUPERVISION) == 0) {
517         if (compName.compare(QAD_Application::getDesktop()->getComponentUserName("SUPERV")) == 0) {
518           SALOMEDS::GenericAttribute_var anAttr;
519           if (obj->FindAttribute(anAttr, "AttributeIOR")) {
520             SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
521             SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value());
522             if (!SUPERV_isNull(aDataFlow)) 
523               theIsDataflow = true;
524           }
525           CORBA::String_var anObjectID = obj->GetID();
526           CORBA::String_var aComponentID = comp->GetID();
527           if (strcmp(anObjectID, aComponentID)) theIsOwner = true;          
528         }
529       }
530     }
531   }
532 }
533
534
535 void SUPERVGUI::deleteObject() {
536   SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
537   if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
538    
539   if (QMessageBox::warning(QAD_Application::getDesktop(),
540                            tr("WARNING"),
541                            tr("MSG_ASK_DELETE"),
542                            QMessageBox::No,
543                            QMessageBox::Yes) == QMessageBox::No)
544     return;
545    
546   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
547   for(;It.More();It.Next()) {
548     Handle(SALOME_InteractiveObject) anIObj = It.Value();
549     bool aIsOwner, aIsDataflow;
550     whatIsSelected(anIObj, aIsOwner, aIsDataflow);
551     
552     SALOMEDS::Study_var aStudy = study->getStudyDocument();
553     SALOMEDS::SObject_var  aObj = aStudy->FindObjectID( anIObj->getEntry() );
554     if (!aObj->_is_nil()) {
555       if (aIsDataflow) {
556         SALOMEDS::GenericAttribute_var anAttr;
557         if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
558           SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
559           QString ior = anIOR->Value();
560             
561           SUPERVGUI_Main* aMain;
562           for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
563             if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
564               aMain->setAsFromStudy(false);
565               break;
566             }
567           }
568         }
569       }
570       QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
571       SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
572       op->start();
573       aBuilder->RemoveObjectWithChildren(aObj);
574       op->finish();
575     }
576   }
577   Sel->ClearIObjects() ; 
578 }
579
580
581
582 void SUPERVGUI::activeStudyChanged() {
583   Trace("SUPERVGUI::activeStudyChanged");
584   study = desktop->getActiveStudy();
585 }
586
587 extern "C" bool OnGUIEvent(int command, QAD_Desktop* parent) {
588     Supervision.init(parent);
589     switch (command) {
590         case 301: 
591             Supervision.importDataflow();
592             return(false);
593         
594         case 302: 
595             Supervision.exportDataflow();
596             return(false);
597         
598         case 303: 
599             Supervision.newDataflow();
600             return(false);
601         
602         case 304: 
603             Supervision.modifyDataflow();
604             return(false);
605         
606         case 305:
607             Supervision.reloadDataflow();
608             return(false);
609         
610         case 306:
611             Supervision.runDataflow();
612             return(false);
613         
614         case 307: 
615             Supervision.killDataflow();
616             return(false);
617         
618         case 308:
619             Supervision.suspendResumeDataflow();
620             return(false);
621         
622         case 309: 
623             Supervision.showComponents();
624             return(false);
625         
626         case 310: 
627             Supervision.stepByStep();
628             return(false);
629         
630         default: 
631             QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome");
632             return(false);
633         
634     }
635 }
636
637 extern "C" bool OnKeyPress(QKeyEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
638     return(false);
639 }
640
641 extern "C" bool OnMousePress(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
642     return(false);
643 }
644
645 extern "C" bool OnMouseMove(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
646     return(false);
647 }
648
649 extern "C" bool OnPopupGUIEvent(int theCommandID, QAD_Desktop* parent) {
650     return(false);
651 }
652
653 extern "C" bool SetSettings(QAD_Desktop* parent) {
654     Trace("extern SUPERVGUI::SetSettings")
655     Supervision.init(parent);
656     return(true);
657 }
658
659 extern "C" void definePopup(QString& theContext, QString& theParent, QString& theObject) {
660     theObject  = "";
661     theContext = "";
662 }
663
664 extern "C" bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
665     Supervision.init(parent);
666     Supervision.customPopup(popup);
667     return(true);
668 }
669
670 extern "C" void activeStudyChanged(QAD_Desktop* parent) {
671     Supervision.activeStudyChanged();
672 }
673
674 extern "C" int supportedViewType()
675 {
676   return (int)VIEW_GRAPHSUPERV;
677 }
678
679 extern "C" void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
680 {
681 }