Salome HOME
5f57e853113e8b748b6f3e052cb562287d71938b
[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 }
96
97
98 QAD_StudyFrame* SUPERVGUI::createGraph() {
99   QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(),
100                                                    VIEW_GRAPHSUPERV, false);
101   if (aStudyFrame) {
102     connect(aStudyFrame, 
103             SIGNAL(sfBeforeStudyFrameClosing(QAD_StudyFrame*)), 
104             &Supervision, 
105             SLOT(onGraphClosed(QAD_StudyFrame*)));
106   }
107   return aStudyFrame;
108 }
109
110
111
112 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
113     Trace("SUPERVGUI::loadEngine")
114     SALOME_LifeCycleCORBA LCC(namingService);
115     Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
116     if (CORBA::is_nil(objComponent)) {
117         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
118         return;
119     };
120
121     SUPERV::SuperG_var aSuperVisionComponent;
122     aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
123     if (CORBA::is_nil(aSuperVisionComponent)) {
124         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
125         return;
126     };
127
128     //    engine  = new SUPERV::SuperG_var;
129     engine = aSuperVisionComponent;
130 }
131 /*
132 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
133     Trace("SUPERVGUI::information")
134     return(info->run(node, isReadOnly));
135 }
136 */
137 void SUPERVGUI::putInfo(const char* mess) {
138     Trace("SUPERVGUI::putInfo")
139     desktop->putInfo(mess);
140 }
141
142 QAD_Desktop* SUPERVGUI::getDesktop() {
143     Trace("SUPERVGUI::getDesktop")
144     return(desktop);
145 }
146
147 SUPERV_Engine SUPERVGUI::getEngine() {
148     Trace("SUPERVGUI::getEngine")
149     return(engine);
150 }
151
152 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
153     Trace("SUPERVGUI::getBrowser")
154     return(browser);
155 }
156
157 QCursor SUPERVGUI::getCursor() {
158     Trace("SUPERVGUI::getCursor")
159     return(cursor);
160 }
161
162 SUPERVGUI_Main* SUPERVGUI::getMain() {
163     Trace("SUPERVGUI::getMain")
164     return main;
165 }
166
167
168 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
169   theGraph->setHashCode(theName);
170   myGraphList.append(theGraph);
171 }
172
173
174 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
175   SUPERVGUI_Main* aMain;
176   for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
177     if (aMain == theGraph)
178       myGraphList.remove(aMain);
179   }
180 }
181
182
183 bool SUPERVGUI::isContains(QAD_Study* theStudy, const QString theKey) {
184   SUPERVGUI_Main* aMain;
185   for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
186     if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
187       return true;
188   }
189   return false;
190 }
191
192
193 void SUPERVGUI::onGraphClosed(QAD_StudyFrame* theStudyFrame) {
194   QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
195   if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
196     disconnect(theStudyFrame, 0 , this, 0);
197     SUPERVGraph_View* view = supervFrame->getViewWidget();
198     SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
199     if (aGraph) {
200       unregisterGraph(aGraph);
201     }
202   }
203 }
204
205 void SUPERVGUI::setMain(QWidget* w) {
206   main = 0;
207   QAD_StudyFrame* aStudyFrame = dynamic_cast<QAD_StudyFrame*>(w);
208   if (!aStudyFrame) return;
209
210   study = aStudyFrame->getStudy();
211   if (!study) return;
212
213   QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame();
214   if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
215     SUPERVGraph_View* view = supervFrame->getViewWidget();
216     if (view)
217       main = dynamic_cast<SUPERVGUI_Main*>(view);
218   }
219   Trace("SUPERVGUI::setMain - main: "<<main);
220 }
221
222
223 void SUPERVGUI::importDataflow() {
224   Trace("SUPERVGUI::importDataflow");
225   QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
226                                        "",
227                                        "*.xml",
228                                        tr("MSG_IMPORT"),
229                                        true);
230   
231   if (!f.isEmpty()) {
232     if (isContains(study, f)) {
233       if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
234                                tr("MSG_GRAPH_DISPLAYED").arg(f), 
235                                QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
236         return;
237     }
238
239     SUPERV_Graph aGraph = engine->GraphE(f);
240     //QFileInfo aFile(f);
241     //aGraph->SetName(aFile.baseName());
242     if (SUPERV_isNull(aGraph)) {
243       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
244       return;
245     }
246
247     QAD_StudyFrame* aStudyFrame = createGraph();
248     SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
249       (aStudyFrame->getRightFrame()->getViewFrame());
250     if(aViewFrame) {
251       main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
252       registerGraph(f, main);
253       study->showFrame(aStudyFrame);
254     }   
255   }
256 }
257
258 void SUPERVGUI::displayDataflow() {
259     Trace("SUPERVGUI::displayDataflow");
260     QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
261     SUPERV_Graph aDataFlow;
262     QString aIORName;
263
264     QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(aBrowser->getListView()->currentItem());
265     SALOMEDS::SObject_var aObj = desktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
266     SALOMEDS::GenericAttribute_var anAttr;
267     if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
268       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
269       Standard_CString ior = anIOR->Value();
270       aIORName = ior;
271       if (isContains(study, aIORName)) {
272         if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
273                                  tr("MSG_GRAPH_DISPLAYED").arg(""), 
274                                  QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
275           return;
276       }
277       aDataFlow = engine->getGraph(ior);
278       if (SUPERV_isNull(aDataFlow)) {
279         QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
280         return;
281       }
282     }
283     QAD_StudyFrame* aStudyFrame = createGraph();
284     SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
285       (aStudyFrame->getRightFrame()->getViewFrame());
286     if(aViewFrame) {
287       main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow);
288       main->setAsFromStudy(true);
289       registerGraph(aIORName, main);
290       study->showFrame(aStudyFrame);
291     }
292 }
293
294
295 void SUPERVGUI::renameDataflow() {
296   SALOME_Selection* Sel = SALOME_Selection::Selection( study->getSelection() );
297   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
298   for ( ; It.More(); It.Next() ) {
299     Handle(SALOME_InteractiveObject) IObject = It.Value();
300     
301     SALOMEDS::Study_var aStudy = study->getStudyDocument();
302     SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
303     SALOMEDS::GenericAttribute_var anAttr;
304     SALOMEDS::AttributeName_var    aName;
305     if ( !obj->_is_nil() ) {
306       if (obj->FindAttribute(anAttr, "AttributeName")) {
307         aName = SALOMEDS::AttributeName::_narrow(anAttr);
308         QString nm = QString( aName->Value() );
309         bool ok = FALSE;
310         nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm );
311         if ( !nm.isEmpty() ) {
312           QApplication::setOverrideCursor( Qt::waitCursor );
313           study->renameIObject( IObject, nm );
314           QApplication::restoreOverrideCursor();
315         }
316       }
317     }
318   }
319 }
320
321
322 void SUPERVGUI::exportDataflow() {
323     Trace("SUPERVGUI::exportDataflow")
324     if (main==0) {
325         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
326     } else {
327       QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
328                                            "",
329                                            "*.xml",
330                                            tr("TTL_EXPORT_DATAFLOW"),
331                                            false);
332       if (!f.isEmpty()) {
333         if (main->exportDataflow(f)) {
334           unregisterGraph(main);
335           registerGraph(f, main);
336         }
337       }
338     }
339 }
340
341 void SUPERVGUI::newDataflow() {
342     Trace("SUPERVGUI::editDataflow");
343     QAD_StudyFrame* aStudyFrame = createGraph();
344     SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
345       (aStudyFrame->getRightFrame()->getViewFrame());
346     if(aViewFrame){
347       main = new SUPERVGUI_Main(aViewFrame, desktop, false);
348       main->addNode();
349       study->showFrame(aStudyFrame);
350     }
351 }
352
353 void SUPERVGUI::modifyDataflow() {
354     Trace("SUPERVGUI::modifyDataflow")
355     QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
356                                          "",
357                                          "*.xml",
358                                          tr("Modify Dataflow"),
359                                          true);
360     if (!f.isEmpty()){
361       if (isContains(study, f)) {
362       if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
363                                tr("MSG_GRAPH_DISPLAYED").arg(f), 
364                                QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
365         return;
366       }
367       
368       SUPERV_Graph aGraph = engine->Graph(f);
369       //QFile aFile(f);
370       //aGraph->SetName(aFile.name());
371       if (SUPERV_isNull(aGraph)) {
372         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
373         return;
374       }
375
376       QAD_StudyFrame* aStudyFrame = createGraph();
377       SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
378         (aStudyFrame->getRightFrame()->getViewFrame());
379       if(aViewFrame) {
380         main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
381         registerGraph(f, main);
382         study->showFrame(aStudyFrame);
383       }
384     }
385 }
386
387 void SUPERVGUI::reloadDataflow() {
388     Trace("SUPERVGUI::reloadDataflow")
389     if (main==0) {
390         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
391     } else {
392         main->sync();
393     };
394 }
395
396 void SUPERVGUI::runDataflow() {
397     Trace("SUPERVGUI::runDataflow")
398     if (main==0) {
399         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
400     } else {
401         main->run();
402     };
403 }
404
405 void SUPERVGUI::stepByStep() {
406     Trace("SUPERVGUI::stepByStep")
407     if (main==0) {
408         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
409     } else {
410         main->startExecute();
411     }
412 }
413
414 void SUPERVGUI::killDataflow() {
415     Trace("SUPERVGUI::killDataflow")
416     if (main==0) {
417         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
418     } else {
419         main->kill();
420     };
421 }
422
423 void SUPERVGUI::suspendResumeDataflow() {
424     Trace("SUPERVGUI::suspendResumeDataflow")
425     if (main==0) {
426         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
427     } else {
428         main->suspendResume();
429     };
430 }
431
432 void SUPERVGUI::showComponents() {
433   Trace("SUPERVGUI::showComponents");
434   if (main==0) {
435     QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
436   } else {
437     if (main->isEditable())
438       main->addNode();
439     else
440       QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
441   }
442 }
443
444 void SUPERVGUI::customPopup(QPopupMenu* popup) {
445   Trace("SUPERVGUI::customPopup");
446   if(popup->count() > 3) {
447     // Temporary code: is to be deleted soon
448     popup->removeItem(QAD_Display_Popup_ID);
449     popup->removeItem(QAD_DisplayOnly_Popup_ID);
450     popup->removeItem(QAD_Erase_Popup_ID);
451     int id = popup->idAt(popup->count() - 1);
452     if (id < 0 && id != -1) popup->removeItem(id); // separator
453     // Temporary code end
454   }
455     SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
456     if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
457
458     if (Sel->IObjectCount() == 1) {
459       Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
460
461       // insert SUPERV-specific popup items here
462
463       bool isDataflow, ownObj;
464       whatIsSelected(anIObj, ownObj, isDataflow);
465       
466       if (isDataflow) {
467         popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
468         popup->insertItem("Display", this, SLOT(displayDataflow()));
469         popup->insertSeparator();
470       }
471       if (ownObj)
472         popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
473     }
474     if (Sel->IObjectCount() > 1) {
475       int aIObjCount = 0;
476       SALOME_ListIteratorOfListIO It_forCheckOwner(Sel->StoredIObjects());
477       for(;It_forCheckOwner.More();It_forCheckOwner.Next()) {
478         Handle(SALOME_InteractiveObject) anIObj = It_forCheckOwner.Value();
479         bool aIsOwner, aIsDataflow;
480         whatIsSelected(anIObj, aIsOwner, aIsDataflow);
481         
482         if (aIsOwner) aIObjCount++;
483       }
484       if (aIObjCount == Sel->IObjectCount())  //all selected objects belong to Supervision
485         popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
486     }
487 }
488
489  
490
491 /** Returns:
492     theIsOwner = true if Selected object belongs to Suipervision.
493     theIsDataflow = true if Selected object is Dataflow
494 */
495 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
496   theIsOwner = false;
497   theIsDataflow = false;
498
499   if (theObj.IsNull()) return;
500   
501   SALOMEDS::Study_var aStudy = study->getStudyDocument();
502   SALOMEDS::SObject_var  obj = aStudy->FindObjectID( theObj->getEntry() );
503
504   if ( !obj->_is_nil() ) {
505     SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
506     if ( !comp->_is_nil() ) {
507       SALOMEDS::GenericAttribute_var anAttr;
508       SALOMEDS::AttributeName_var    aName;
509       if (comp->FindAttribute(anAttr, "AttributeName")) {
510         aName = SALOMEDS::AttributeName::_narrow(anAttr);
511         QString compName(aName->Value());
512         //if (compName.compare(STUDY_SUPERVISION) == 0) {
513         if (compName.compare(QAD_Application::getDesktop()->getComponentUserName("SUPERV")) == 0) {
514           SALOMEDS::GenericAttribute_var anAttr;
515           if (obj->FindAttribute(anAttr, "AttributeIOR")) {
516             SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
517             SUPERV_Graph aDataFlow = engine->getGraph(anIOR->Value());
518             if (!SUPERV_isNull(aDataFlow)) 
519               theIsDataflow = true;
520           }
521           CORBA::String_var anObjectID = obj->GetID();
522           CORBA::String_var aComponentID = comp->GetID();
523           if (strcmp(anObjectID, aComponentID)) theIsOwner = true;          
524         }
525       }
526     }
527   }
528 }
529
530
531 void SUPERVGUI::deleteObject() {
532   SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
533   if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
534    
535   if (QMessageBox::warning(QAD_Application::getDesktop(),
536                            tr("WARNING"),
537                            tr("MSG_ASK_DELETE"),
538                            QMessageBox::No,
539                            QMessageBox::Yes) == QMessageBox::No)
540     return;
541    
542   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
543   for(;It.More();It.Next()) {
544     Handle(SALOME_InteractiveObject) anIObj = It.Value();
545     bool aIsOwner, aIsDataflow;
546     whatIsSelected(anIObj, aIsOwner, aIsDataflow);
547     
548     SALOMEDS::Study_var aStudy = study->getStudyDocument();
549     SALOMEDS::SObject_var  aObj = aStudy->FindObjectID( anIObj->getEntry() );
550     if (!aObj->_is_nil()) {
551       if (aIsDataflow) {
552         SALOMEDS::GenericAttribute_var anAttr;
553         if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
554           SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
555           QString ior = anIOR->Value();
556             
557           SUPERVGUI_Main* aMain;
558           for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
559             if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
560               aMain->setAsFromStudy(false);
561               break;
562             }
563           }
564         }
565       }
566       QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
567       SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
568       op->start();
569       aBuilder->RemoveObjectWithChildren(aObj);
570       op->finish();
571     }
572   }
573   Sel->ClearIObjects() ; 
574 }
575
576
577
578 void SUPERVGUI::activeStudyChanged() {
579   Trace("SUPERVGUI::activeStudyChanged");
580   study = desktop->getActiveStudy();
581 }
582
583 extern "C" bool OnGUIEvent(int command, QAD_Desktop* parent) {
584     Supervision.init(parent);
585     switch (command) {
586         case 301: 
587             Supervision.importDataflow();
588             return(false);
589         
590         case 302: 
591             Supervision.exportDataflow();
592             return(false);
593         
594         case 303: 
595             Supervision.newDataflow();
596             return(false);
597         
598         case 304: 
599             Supervision.modifyDataflow();
600             return(false);
601         
602         case 305:
603             Supervision.reloadDataflow();
604             return(false);
605         
606         case 306:
607             Supervision.runDataflow();
608             return(false);
609         
610         case 307: 
611             Supervision.killDataflow();
612             return(false);
613         
614         case 308:
615             Supervision.suspendResumeDataflow();
616             return(false);
617         
618         case 309: 
619             Supervision.showComponents();
620             return(false);
621         
622         case 310: 
623             Supervision.stepByStep();
624             return(false);
625         
626         default: 
627             QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome");
628             return(false);
629         
630     }
631 }
632
633 extern "C" bool OnKeyPress(QKeyEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
634     return(false);
635 }
636
637 extern "C" bool OnMousePress(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
638     return(false);
639 }
640
641 extern "C" bool OnMouseMove(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
642     return(false);
643 }
644
645 extern "C" bool OnPopupGUIEvent(int theCommandID, QAD_Desktop* parent) {
646     return(false);
647 }
648
649 extern "C" bool SetSettings(QAD_Desktop* parent) {
650     Trace("extern SUPERVGUI::SetSettings")
651     Supervision.init(parent);
652     return(true);
653 }
654
655 extern "C" void definePopup(QString& theContext, QString& theParent, QString& theObject) {
656     theObject  = "";
657     theContext = "";
658 }
659
660 extern "C" bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
661     Supervision.init(parent);
662     Supervision.customPopup(popup);
663     return(true);
664 }
665
666 extern "C" void activeStudyChanged(QAD_Desktop* parent) {
667     Supervision.activeStudyChanged();
668 }
669
670 extern "C" int supportedViewType()
671 {
672   return (int)VIEW_GRAPHSUPERV;
673 }
674
675 extern "C" void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
676 {
677 }