1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI.h"
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"
48 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
51 int SUPERVGUI::factory = 0;
52 SUPERVGUI Supervision;
55 SUPERVGUI::SUPERVGUI(): QObject(),
62 Trace("SUPERVGUI::SUPERVGUI")
65 MESSAGE("SUPERVGUI Info : factory build");
67 MESSAGE("SUPERVGUI Error : another call to factory constructor");
71 SUPERVGUI::~SUPERVGUI() {
72 Trace("SUPERVGUI::~SUPERVGUI")
77 MESSAGE("SUPERVGUI Info : factory destroy");
79 MESSAGE("SUPERVGUI Error : another call to factory destructor");
83 void SUPERVGUI::init(QAD_Desktop* parent) {
84 Trace("SUPERVGUI::init")
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*)));
98 QAD_StudyFrame* SUPERVGUI::createGraph() {
99 QAD_StudyFrame* aStudyFrame = study->newWindow3d(study->getNextStudyFrameName(),
100 VIEW_GRAPHSUPERV, false);
103 SIGNAL(sfBeforeStudyFrameClosing(QAD_StudyFrame*)),
105 SLOT(onGraphClosed(QAD_StudyFrame*)));
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", "Supervision");
116 if (CORBA::is_nil(objComponent)) {
117 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_LOAD_SUPERV"));
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"));
128 engine = new SUPERV::SuperG_var;
129 *engine = aSuperVisionComponent;
132 bool SUPERVGUI::information(SUPERV_CNode node, bool isReadOnly) {
133 Trace("SUPERVGUI::information")
134 return(info->run(node, isReadOnly));
137 void SUPERVGUI::putInfo(const char* mess) {
138 Trace("SUPERVGUI::putInfo")
139 desktop->putInfo(mess);
142 QAD_Desktop* SUPERVGUI::getDesktop() {
143 Trace("SUPERVGUI::getDesktop")
147 SUPERV_Engine SUPERVGUI::getEngine() {
148 Trace("SUPERVGUI::getEngine")
152 SUPERVGUI_Service* SUPERVGUI::getBrowser() {
153 Trace("SUPERVGUI::getBrowser")
157 QCursor SUPERVGUI::getCursor() {
158 Trace("SUPERVGUI::getCursor")
162 SUPERVGUI_Main* SUPERVGUI::getMain() {
163 Trace("SUPERVGUI::getMain")
168 void SUPERVGUI::registerGraph(QString theName, SUPERVGUI_Main* theGraph){
169 theGraph->setHashCode(theName);
170 myGraphList.append(theGraph);
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);
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))
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);
200 unregisterGraph(aGraph);
205 void SUPERVGUI::setMain(QWidget* w) {
207 QAD_StudyFrame* aStudyFrame = dynamic_cast<QAD_StudyFrame*>(w);
208 if (!aStudyFrame) return;
210 study = aStudyFrame->getStudy();
213 QAD_ViewFrame* viewFrame = aStudyFrame->getRightFrame()->getViewFrame();
214 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
215 SUPERVGraph_View* view = supervFrame->getViewWidget();
217 main = dynamic_cast<SUPERVGUI_Main*>(view);
219 Trace("SUPERVGUI::setMain - main: "<<main);
223 void SUPERVGUI::importDataflow() {
224 Trace("SUPERVGUI::importDataflow");
225 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
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)
239 SUPERV_Graph aGraph = (*Supervision.getEngine())->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));
247 QAD_StudyFrame* aStudyFrame = createGraph();
248 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
249 (aStudyFrame->getRightFrame()->getViewFrame());
251 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
252 registerGraph(f, main);
253 study->showFrame(aStudyFrame);
258 void SUPERVGUI::displayDataflow() {
259 Trace("SUPERVGUI::displayDataflow");
260 QAD_ObjectBrowser* aBrowser = ((QAD_StudyFrame*)(desktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
261 SUPERV_Graph aDataFlow;
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();
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)
277 aDataFlow = (*Supervision.getEngine())->getGraph(ior);
278 if (SUPERV_isNull(aDataFlow)) {
279 QMessageBox::warning(0, tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
283 QAD_StudyFrame* aStudyFrame = createGraph();
284 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
285 (aStudyFrame->getRightFrame()->getViewFrame());
287 main = new SUPERVGUI_Main(aViewFrame, desktop, aDataFlow);
288 main->setAsFromStudy(true);
289 registerGraph(aIORName, main);
290 study->showFrame(aStudyFrame);
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();
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() );
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();
322 void SUPERVGUI::exportDataflow() {
323 Trace("SUPERVGUI::exportDataflow")
325 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_EXPORT"));
327 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
330 tr("TTL_EXPORT_DATAFLOW"),
333 if (main->exportDataflow(f)) {
334 unregisterGraph(main);
335 registerGraph(f, main);
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());
347 main = new SUPERVGUI_Main(aViewFrame, desktop, false);
349 study->showFrame(aStudyFrame);
353 void SUPERVGUI::modifyDataflow() {
354 Trace("SUPERVGUI::modifyDataflow")
355 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
358 tr("Modify Dataflow"),
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)
368 SUPERV_Graph aGraph = (*Supervision.getEngine())->Graph(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));
376 QAD_StudyFrame* aStudyFrame = createGraph();
377 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
378 (aStudyFrame->getRightFrame()->getViewFrame());
380 main = new SUPERVGUI_Main(aViewFrame, desktop, aGraph);
381 registerGraph(f, main);
382 study->showFrame(aStudyFrame);
387 void SUPERVGUI::reloadDataflow() {
388 Trace("SUPERVGUI::reloadDataflow")
390 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RELOAD"));
396 void SUPERVGUI::runDataflow() {
397 Trace("SUPERVGUI::runDataflow")
399 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
405 void SUPERVGUI::stepByStep() {
406 Trace("SUPERVGUI::stepByStep")
408 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_RUN"));
410 main->startExecute();
414 void SUPERVGUI::killDataflow() {
415 Trace("SUPERVGUI::killDataflow")
417 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_KILL"));
423 void SUPERVGUI::suspendResumeDataflow() {
424 Trace("SUPERVGUI::suspendResumeDataflow")
426 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_SUSPEND"));
428 main->suspendResume();
432 void SUPERVGUI::showComponents() {
433 Trace("SUPERVGUI::showComponents");
435 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOWINDOW_TO_ADD"));
437 if (main->isEditable())
440 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTEDITABLE"));
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
455 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
456 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
458 Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
460 // insert SUPERV-specific popup items here
462 bool isDataflow, ownObj;
463 whatIsSelected(anIObj, ownObj, isDataflow);
466 popup->insertItem(tr( "MSG_RENAME" ), this, SLOT(renameDataflow()));
467 popup->insertItem("Display", this, SLOT(displayDataflow()));
468 popup->insertSeparator();
471 popup->insertItem(tr("MSG_DELETE"), this, SLOT(deleteObject()));
477 theIsOwner = true if Selected object belongs to Suipervision.
478 theIsDataflow = true if Selected object is Dataflow
480 void SUPERVGUI::whatIsSelected(const Handle(SALOME_InteractiveObject)& theObj, bool& theIsOwner, bool& theIsDataflow) {
482 theIsDataflow = false;
484 if (theObj.IsNull()) return;
486 SALOMEDS::Study_var aStudy = study->getStudyDocument();
487 SALOMEDS::SObject_var obj = aStudy->FindObjectID( theObj->getEntry() );
489 if ( !obj->_is_nil() ) {
490 SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
491 if ( !comp->_is_nil() ) {
492 SALOMEDS::GenericAttribute_var anAttr;
493 SALOMEDS::AttributeName_var aName;
494 if (comp->FindAttribute(anAttr, "AttributeName")) {
495 aName = SALOMEDS::AttributeName::_narrow(anAttr);
496 QString compName(aName->Value());
497 // if (compName.compare(STUDY_SUPERVISION) == 0) {
498 if (compName.compare( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) == 0) {
499 SALOMEDS::GenericAttribute_var anAttr;
500 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
501 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
502 SUPERV_Graph aDataFlow = (*Supervision.getEngine())->getGraph(anIOR->Value());
503 if (!SUPERV_isNull(aDataFlow))
504 theIsDataflow = true;
506 CORBA::String_var anObjectID = obj->GetID();
507 CORBA::String_var aComponentID = comp->GetID();
508 if (strcmp(anObjectID, aComponentID)) theIsOwner = true;
516 void SUPERVGUI::deleteObject() {
517 SALOME_Selection* Sel = SALOME_Selection::Selection(study->getSelection() );
518 if ((Sel==NULL) || (Sel->IObjectCount() == 0)) return;
520 Handle(SALOME_InteractiveObject) anIObj = Sel->firstIObject();
521 bool aIsOwner, aIsDataflow;
522 whatIsSelected(anIObj, aIsOwner, aIsDataflow);
524 if (!aIsOwner) return;
526 if (QMessageBox::warning(QAD_Application::getDesktop(),
528 tr("MSG_ASK_DELETE"),
530 QMessageBox::Yes) == QMessageBox::No)
533 SALOMEDS::Study_var aStudy = study->getStudyDocument();
534 SALOMEDS::SObject_var aObj = aStudy->FindObjectID( anIObj->getEntry() );
535 if (!aObj->_is_nil()) {
537 SALOMEDS::GenericAttribute_var anAttr;
538 if (aObj->FindAttribute(anAttr, "AttributeIOR")) {
539 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
540 QString ior = anIOR->Value();
542 SUPERVGUI_Main* aMain;
543 for (aMain = myGraphList.first(); aMain; aMain = myGraphList.next()) {
544 if ((aMain->getStudy() == study) && (aMain->getHashCode() == ior)) {
545 aMain->setAsFromStudy(false);
551 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
552 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
554 aBuilder->RemoveObjectWithChildren(aObj);
557 Sel->ClearIObjects() ;
562 void SUPERVGUI::activeStudyChanged() {
563 Trace("SUPERVGUI::activeStudyChanged");
564 study = desktop->getActiveStudy();
567 extern "C" bool OnGUIEvent(int command, QAD_Desktop* parent) {
568 Supervision.init(parent);
571 Supervision.importDataflow();
575 Supervision.exportDataflow();
579 Supervision.newDataflow();
583 Supervision.modifyDataflow();
587 Supervision.reloadDataflow();
591 Supervision.runDataflow();
595 Supervision.killDataflow();
599 Supervision.suspendResumeDataflow();
603 Supervision.showComponents();
607 Supervision.stepByStep();
611 QMessageBox::warning(QAD_Application::getDesktop(), "Supervision Error", "Unknown Command From Salome");
617 extern "C" bool OnKeyPress(QKeyEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
621 extern "C" bool OnMousePress(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
625 extern "C" bool OnMouseMove(QMouseEvent* e, QAD_Desktop* parent, SUPERVGUI_Main* s) {
629 extern "C" bool OnPopupGUIEvent(int theCommandID, QAD_Desktop* parent) {
633 extern "C" bool SetSettings(QAD_Desktop* parent) {
634 Trace("extern SUPERVGUI::SetSettings")
635 Supervision.init(parent);
639 extern "C" void definePopup(QString& theContext, QString& theParent, QString& theObject) {
644 extern "C" bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) {
645 Supervision.init(parent);
646 Supervision.customPopup(popup);
650 extern "C" void activeStudyChanged(QAD_Desktop* parent) {
651 Supervision.activeStudyChanged();
654 extern "C" int supportedViewType()
656 return (int)VIEW_GRAPHSUPERV;