2 // File : SUPERVGUI.cxx
3 // Created : 31 octobre 2001
4 // Author : Francis KLOSS
11 #include "QAD_Resource.h"
12 #include "QAD_FileDlg.h"
13 #include "QAD_Application.h"
14 #include "QAD_StudyFrame.h"
15 #include "QAD_RightFrame.h"
16 #include "QAD_LeftFrame.h"
17 #include "QAD_ViewFrame.h"
18 #include "QAD_ObjectBrowser.h"
19 #include "QAD_ObjectBrowserItem.h"
20 #include "SALOME_Selection.h"
21 #include "SALOMEGUI_NameDlg.h"
22 #include "Utils_ORB_INIT.hxx"
23 #include "SALOME_ListIteratorOfListIO.hxx"
24 #include "SALOME_InteractiveObject.hxx"
25 #include <qapplication.h>
26 #include "SALOMEGUI_ImportOperation.h"
28 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
31 int SUPERVGUI::factory = 0;
32 SUPERVGUI Supervision;
35 SUPERVGUI::SUPERVGUI(): QObject(),
42 Trace("SUPERVGUI::SUPERVGUI")
45 MESSAGE("SUPERVGUI Info : factory build");
47 MESSAGE("SUPERVGUI Error : another call to factory constructor");
51 SUPERVGUI::~SUPERVGUI() {
52 Trace("SUPERVGUI::~SUPERVGUI")
57 MESSAGE("SUPERVGUI Info : factory destroy");
59 MESSAGE("SUPERVGUI Error : another call to factory destructor");
63 void SUPERVGUI::init(QAD_Desktop* parent) {
64 Trace("SUPERVGUI::init")
67 study = desktop->getActiveStudy();
68 SALOME_NamingService* namingService = desktop->getNameService();
69 loadEngine(namingService);
70 browser = new SUPERVGUI_Service(namingService);
71 //info = new SUPERVGUI_Information();
72 cursor = desktop->cursor();
73 connect(desktop->getMainFrame(), SIGNAL(windowActivated(QWidget*)), this, SLOT(setMain(QWidget*)));
78 QAD_StudyFrame* SUPERVGUI::createGraph() {
79 QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(),
80 VIEW_GRAPHSUPERV, false);
83 SIGNAL(sfBeforeStudyFrameClosing(QAD_StudyFrame*)),
85 SLOT(onGraphClosed(QAD_StudyFrame*)));
92 void SUPERVGUI::loadEngine(SALOME_NamingService* namingService) {
93 Trace("SUPERVGUI::loadEngine")
94 SALOME_LifeCycleCORBA LCC(namingService);
95 Engines::Component_var objComponent = LCC.FindOrLoad_Component("SuperVisionContainer", "SUPERV");
96 if (CORBA::is_nil(objComponent)) {
97 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
101 SUPERV::SuperG_var aSuperVisionComponent;
102 aSuperVisionComponent = SUPERV::SuperG::_narrow(objComponent);
103 if (CORBA::is_nil(aSuperVisionComponent)) {
104 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_NARROW_SUPERV"));
108 engine = new SUPERV::SuperG_var;
109 *engine = aSuperVisionComponent;
112 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
113 Trace("SUPERVGUI::information")
114 return(info->run(node, isReadOnly));
117 void SUPERVGUI::putInfo(const char* mess) {
118 Trace("SUPERVGUI::putInfo")
119 desktop->putInfo(mess);
122 QAD_Desktop* SUPERVGUI::getDesktop() {
123 Trace("SUPERVGUI::getDesktop")
127 SUPERV_Engine SUPERVGUI::getEngine() {
128 Trace("SUPERVGUI::getEngine")
132 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
133 Trace("SUPERVGUI::getBrowser")
137 QCursor SUPERVGUI::getCursor() {
138 Trace("SUPERVGUI::getCursor")
142 SUPERVGUI_Main* SUPERVGUI::getMain() {
143 Trace("SUPERVGUI::getMain")
148 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
149 theGraph->setHashCode(theName);
150 myGraphList.append(theGraph);
154 void SUPERVGUI::unregisterGraph(SUPERVGUI_Main* theGraph) {
155 SUPERVGUI_Main* aMain;
156 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
157 if (aMain == theGraph)
158 myGraphList.remove(aMain);
163 bool SUPERVGUI::isContains(QAD_Study* theStudy, const QString theKey) {
164 SUPERVGUI_Main* aMain;
165 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
166 if ((aMain->getStudy() == theStudy) && (aMain->getHashCode() == theKey))
173 void SUPERVGUI::onGraphClosed(QAD_StudyFrame* theStudyFrame) {
174 QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
175 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
176 disconnect(theStudyFrame, 0 , this, 0);
177 SUPERVGraph_View* view = supervFrame->getViewWidget();
178 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
180 unregisterGraph(aGraph);
185 void SUPERVGUI::setMain(QWidget* w) {
187 QAD_StudyFrame* aStudyFrame = dynamic_cast<QAD_StudyFrame*>(w);
188 if (!aStudyFrame) return;
190 study = aStudyFrame->getStudy();
193 QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame();
194 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
195 SUPERVGraph_View* view = supervFrame->getViewWidget();
197 main = dynamic_cast<SUPERVGUI_Main*>(view);
199 Trace("SUPERVGUI::setMain - main: "<<main);
203 void SUPERVGUI::importDataflow() {
204 Trace("SUPERVGUI::importDataflow");
205 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
212 if (isContains(study, f)) {
213 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
214 tr("MSG_GRAPH_DISPLAYED").arg(f),
215 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
219 SUPERV_Graph aGraph = (*Supervision.getEngine())->GraphE(f);
220 //QFileInfo aFile(f);
221 //aGraph->SetName(aFile.baseName());
222 if (SUPERV_isNull(aGraph)) {
223 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
227 QAD_StudyFrame* aStudyFrame = createGraph();
228 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
229 (aStudyFrame->getRightFrame()->getViewFrame());
231 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
232 registerGraph(f, main);
233 study->showFrame(aStudyFrame);
238 void SUPERVGUI::displayDataflow() {
239 Trace("SUPERVGUI::displayDataflow");
240 QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
241 SUPERV_Graph aDataFlow;
244 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(aBrowser->getListView()->currentItem());
245 SALOMEDS::SObject_var aObj = desktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
246 SALOMEDS::GenericAttribute_var anAttr;
247 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
248 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
249 Standard_CString ior = anIOR->Value();
251 if (isContains(study, aIORName)) {
252 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
253 tr("MSG_GRAPH_DISPLAYED").arg(""),
254 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
257 aDataFlow = (*Supervision.getEngine())->getGraph(ior);
258 if (SUPERV_isNull(aDataFlow)) {
259 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
263 QAD_StudyFrame* aStudyFrame = createGraph();
264 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
265 (aStudyFrame->getRightFrame()->getViewFrame());
267 main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow);
268 main->setAsFromStudy(true);
269 registerGraph(aIORName, main);
270 study->showFrame(aStudyFrame);
275 void SUPERVGUI::renameDataflow() {
276 SALOME_Selection* Sel = SALOME_Selection::Selection( study->getSelection() );
277 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
278 for ( ; It.More(); It.Next() ) {
279 Handle(SALOME_InteractiveObject) IObject = It.Value();
281 SALOMEDS::Study_var aStudy = study->getStudyDocument();
282 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
283 SALOMEDS::GenericAttribute_var anAttr;
284 SALOMEDS::AttributeName_var aName;
285 if ( !obj->_is_nil() ) {
286 if (obj->FindAttribute(anAttr, "AttributeName")) {
287 aName = SALOMEDS::AttributeName::_narrow(anAttr);
288 QString nm = QString( aName->Value() );
290 nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm );
291 if ( !nm.isEmpty() ) {
292 QApplication::setOverrideCursor( Qt::waitCursor );
293 study->renameIObject( IObject, nm );
294 QApplication::restoreOverrideCursor();
302 void SUPERVGUI::exportDataflow() {
303 Trace("SUPERVGUI::exportDataflow")
305 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
307 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
310 tr("TTL_EXPORT_DATAFLOW"),
313 if (main->exportDataflow(f)) {
314 unregisterGraph(main);
315 registerGraph(f, main);
321 void SUPERVGUI::newDataflow() {
322 Trace("SUPERVGUI::editDataflow");
323 QAD_StudyFrame* aStudyFrame = createGraph();
324 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
325 (aStudyFrame->getRightFrame()->getViewFrame());
327 main = new SUPERVGUI_Main(aViewFrame, desktop, false);
329 study->showFrame(aStudyFrame);
333 void SUPERVGUI::modifyDataflow() {
334 Trace("SUPERVGUI::modifyDataflow")
335 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
338 tr("Modify Dataflow"),
341 if (isContains(study, f)) {
342 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
343 tr("MSG_GRAPH_DISPLAYED").arg(f),
344 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
348 SUPERV_Graph aGraph = (*Supervision.getEngine())->Graph(f);
350 //aGraph->SetName(aFile.name());
351 if (SUPERV_isNull(aGraph)) {
352 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
356 QAD_StudyFrame* aStudyFrame = createGraph();
357 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
358 (aStudyFrame->getRightFrame()->getViewFrame());
360 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
361 registerGraph(f, main);
362 study->showFrame(aStudyFrame);
367 void SUPERVGUI::reloadDataflow() {
368 Trace("SUPERVGUI::reloadDataflow")
370 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
376 void SUPERVGUI::runDataflow() {
377 Trace("SUPERVGUI::runDataflow")
379 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
385 void SUPERVGUI::stepByStep() {
386 Trace("SUPERVGUI::stepByStep")
388 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
390 main->startExecute();
394 void SUPERVGUI::killDataflow() {
395 Trace("SUPERVGUI::killDataflow")
397 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
403 void SUPERVGUI::suspendResumeDataflow() {
404 Trace("SUPERVGUI::suspendResumeDataflow")
406 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
408 main->suspendResume();
412 void SUPERVGUI::showComponents() {
413 Trace("SUPERVGUI::showComponents");
415 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
417 if (main->isEditable())
420 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
424 void SUPERVGUI::customPopup(QPopupMenu* popup) {
425 Trace("SUPERVGUI::customPopup");
426 if(popup->count() > 3) {
427 // Temporary code: is to be deleted soon
428 popup->removeItem(QAD_Display_Popup_ID);
429 popup->removeItem(QAD_DisplayOnly_Popup_ID);
430 popup->removeItem(QAD_Erase_Popup_ID);
431 int id = popup->idAt(popup->count() - 1);
432 if (id < 0 && id != -1) popup->removeItem(id); // separator
433 // Temporary code end
435 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
436 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
438 Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
440 // insert SUPERV-specific popup items here
442 bool isDataflow, ownObj;
443 whatIsSelected(anIObj, ownObj, isDataflow);
446 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
447 popup->insertItem("Display", this, SLOT(displayDataflow()));
448 popup->insertSeparator();
451 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
457 theIsOwner = true if Selected object belongs to Suipervision.
458 theIsDataflow = true if Selected object is Dataflow
460 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
462 theIsDataflow = false;
464 if (theObj.IsNull()) return;
466 SALOMEDS::Study_var aStudy = study->getStudyDocument();
467 SALOMEDS::SObject_var obj = aStudy->FindObjectID( theObj->getEntry() );
469 if ( !obj->_is_nil() ) {
470 SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
471 if ( !comp->_is_nil() ) {
472 SALOMEDS::GenericAttribute_var anAttr;
473 SALOMEDS::AttributeName_var aName;
474 if (comp->FindAttribute(anAttr, "AttributeName")) {
475 aName = SALOMEDS::AttributeName::_narrow(anAttr);
476 QString compName(aName->Value());
477 if (compName.compare(STUDY_SUPERVISION) == 0) {
478 SALOMEDS::GenericAttribute_var anAttr;
479 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
480 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
481 SUPERV_Graph aDataFlow = (*Supervision.getEngine())->getGraph(anIOR->Value());
482 if (!SUPERV_isNull(aDataFlow))
483 theIsDataflow = true;
485 CORBA::String_var anObjectID = obj->GetID();
486 CORBA::String_var aComponentID = comp->GetID();
487 if (strcmp(anObjectID, aComponentID)) theIsOwner = true;
495 void SUPERVGUI::deleteObject() {
496 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
497 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
499 Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
500 bool aIsOwner, aIsDataflow;
501 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
503 if (!aIsOwner) return;
505 if (QMessageBox::warning(QAD_Application::getDesktop(),
507 tr("MSG_ASK_DELETE"),
509 QMessageBox::Yes) == QMessageBox::No)
512 SALOMEDS::Study_var aStudy = study->getStudyDocument();
513 SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() );
514 if (!aObj->_is_nil()) {
516 SALOMEDS::GenericAttribute_var anAttr;
517 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
518 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
519 QString ior = anIOR->Value();
521 SUPERVGUI_Main* aMain;
522 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
523 if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
524 aMain->setAsFromStudy(false);
530 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
531 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
533 aBuilder->RemoveObjectWithChildren(aObj);
536 Sel->ClearIObjects() ;
541 void SUPERVGUI::activeStudyChanged() {
542 Trace("SUPERVGUI::activeStudyChanged");
543 study = desktop->getActiveStudy();
546 extern "C" bool OnGUIEvent(int command, QAD_Desktop* parent) {
547 Supervision.init(parent);
550 Supervision.importDataflow();
554 Supervision.exportDataflow();
558 Supervision.newDataflow();
562 Supervision.modifyDataflow();
566 Supervision.reloadDataflow();
570 Supervision.runDataflow();
574 Supervision.killDataflow();
578 Supervision.suspendResumeDataflow();
582 Supervision.showComponents();
586 Supervision.stepByStep();
590 QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome");
596 extern "C" bool OnKeyPress(QKeyEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
600 extern "C" bool OnMousePress(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
604 extern "C" bool OnMouseMove(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
608 extern "C" bool OnPopupGUIEvent(int theCommandID, QAD_Desktop* parent) {
612 extern "C" bool SetSettings(QAD_Desktop* parent) {
613 Trace("extern SUPERVGUI::SetSettings")
614 Supervision.init(parent);
618 extern "C" void definePopup(QString& theContext, QString& theParent, QString& theObject) {
623 extern "C" bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
624 Supervision.init(parent);
625 Supervision.customPopup(popup);
629 extern "C" void activeStudyChanged(QAD_Desktop* parent) {
630 // Supervision.activeStudyChanged();
633 extern "C" int supportedViewType()
635 return (int)VIEW_GRAPHSUPERV;