#include "SUPERVGUI_CanvasNode.h"
#include "SUPERVGUI_CanvasNodePrs.h"
#include "SUPERVGUI_CanvasPort.h"
+#include "SUPERVGUI_Clipboard.h"
#include "SUPERVGUI_Main.h"
-#include "SUPERVGUI_Python.h"
#include "SUPERVGUI.h"
#include "SUPERVGUI_BrowseNodeDlg.h"
-#include "SALOMEGUI_NameDlg.h"
+#include "SUPERVGUI_ManagePortsDlg.h"
#include "SUPERVGUI_Information.h"
-/*
-#include "SUPERVGUI_CanvasControlNode.h"
+#include "SUPERVGUI_Library.h"
-#include <qtooltip.h>
-*/
+#include "SALOMEGUI_NameDlg.h"
+#include "QAD_MessageBox.h"
+#include "QAD_Message.h"
-SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
+
+SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode, bool theIsCell):
QObject(theParent),
myMain(theMain),
myNode(theNode),
myLabelText = aNewComment;
- // create node ports
- isIgnore = true;
- //cout << " get port list... " ;
- SUPERV_Ports aPortList = myNode->Ports();
- //cout << aPortList->length() << endl;
- for (int i = 0; i < aPortList->length(); i++) {
- createPort(aPortList[i].in());
- }
-
- //cout << " get stream port list... " ;
- SUPERV_StreamPorts aStreamPortList = myNode->StreamPorts();
- //cout << aStreamPortList->length() << endl;
- for (int i = 0; i < aStreamPortList->length(); i++) {
- createStreamPort(aStreamPortList[i].in());
+ // mkr : if the SUPERVGUI_CavasCellNode created (for CANVASTABLE view),
+ // we don't create the ports
+ if (!theIsCell) {
+ // create node ports
+ isIgnore = true;
+ SUPERV_Ports aPortList = myNode->Ports();
+ for (int i = 0; i < aPortList->length(); i++)
+ createPort(aPortList[i].in());
+
+ SUPERV_StreamPorts aStreamPortList = myNode->StreamPorts();
+ for (int i = 0; i < aStreamPortList->length(); i++) {
+ createStreamPort(aStreamPortList[i].in());
+ }
}
isIgnore = false;
SUPERVGUI_CanvasNode::~SUPERVGUI_CanvasNode()
{
isIgnore = true;
- if (myPrs) delete myPrs;
+ if ( myPrs ) {
+ myPrs->hide();
+ delete myPrs;
+ myPrs = 0;
+ }
}
void SUPERVGUI_CanvasNode::setDestroyed()
getPrs()->hide();
}
-SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasNode::getPrs() const
+SUPERVGUI_CanvasNodePrs* SUPERVGUI_CanvasNode::getPrs()
{
- if (myPrs == 0) {
- ((SUPERVGUI_CanvasNode*)this)->myPrs = createPrs();
- }
+ if ( !myPrs )
+ myPrs = createPrs();
+
return myPrs;
}
return new SUPERVGUI_CanvasNodePrs(myMain->getCanvas(), (SUPERVGUI_CanvasNode*)this);
}
-void SUPERVGUI_CanvasNode::createPort(SUPERV::Port_ptr thePort) const
+void SUPERVGUI_CanvasNode::createPort(SUPERV::Port_ptr thePort)
{
SUPERVGUI_CanvasPort* aPort = 0;
if (thePort->IsInput())
}
}
-void SUPERVGUI_CanvasNode::createStreamPort(SUPERV::StreamPort_ptr thePort) const
+void SUPERVGUI_CanvasNode::createStreamPort(SUPERV::StreamPort_ptr thePort)
{
SUPERVGUI_CanvasPort* aPort = 0;
if (thePort->IsInput())
QPopupMenu* SUPERVGUI_CanvasNode::getPopupMenu(QWidget* theParent)
{
QPopupMenu* popup = new QPopupMenu(theParent);
- if (myMain->getDataflow()->IsExecuting()) {
- popup->insertItem((myNode->IsSuspended()?tr("MSG_RESUME"):tr("MSG_SUSPEND")),
- this, SLOT(suspendResume()));
+
+ if (myMain->getDataflow()->IsExecuting()) { // Execution time
+ popup->insertItem((myNode->IsSuspended()?tr("MSG_RESUME"):tr("MSG_SUSPEND")), this, SLOT(suspendResume()));
popup->insertItem(tr("MSG_KILL"), this, SLOT(kill()));
}
- else {
- if (myMain->isEditable() && getNodeType() != SUPERV::EndLoopNode
- && getNodeType() != SUPERV::EndSwitchNode) {
+ else { // Edition time
+ const int type = getNodeType();
+
+ // for all nodes except EndLoop and EndSwitch : Rename, Delete, Copy
+ if ( myMain->isEditable() && type != SUPERV::EndLoopNode && type != SUPERV::EndSwitchNode &&
+ // asv 26.01.05 : don't allow nodes "edition" commands in Table view
+ myMain->getViewType() != CANVASTABLE ) {
popup->insertItem(tr("MSG_RENAME"), this, SLOT(rename()));
popup->insertItem(tr("MSG_DELETE"), this, SLOT(remove()));
- popup->insertSeparator();
}
+
+ // tmp: Copy temporary does not work for Macro nodes...
+ if ( type != SUPERV::MacroNode )
+ popup->insertItem(tr("ITM_COPY_NODE"), this, SLOT(copy())); // Copy Node functionality
+ popup->insertSeparator();
+
+ // for all nodes : Browse
popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
- if (getNodeType() != SUPERV::EndLoopNode &&
- getNodeType() != SUPERV::EndSwitchNode)
+ // for all nodes except EndLoop and EndSwitch : Change info
+ if (type != SUPERV::EndLoopNode && type != SUPERV::EndSwitchNode)
popup->insertItem(tr("MSG_CHANGE_INFO"), this, SLOT(changeInformation()));
- if (myMain->isEditable() && getNodeType() != SUPERV::FactoryNode
- && getNodeType() != SUPERV::ComputingNode
- && getNodeType() != SUPERV::EndLoopNode
- && getNodeType() != SUPERV::MacroNode) {
- QPopupMenu* addPortMenu = new QPopupMenu(theParent);
- addPortMenu->insertItem("Input", this, SLOT(addInputPort()));
- if (getNodeType() != SUPERV::LoopNode)
- addPortMenu->insertItem("Output", this, SLOT(addOutputPort()));
-
- popup->insertSeparator();
- if ((getNodeType() != SUPERV::EndSwitchNode))
- popup->insertItem("Edit Function", this, SLOT(editFunction()));
- popup->insertItem("Add Port", addPortMenu);
+ // for all InLine nodes
+ if ( type != SUPERV::FactoryNode && type != SUPERV::ComputingNode && type != SUPERV::MacroNode ) {
+ if ( myMain->isEditable() ) {
+ popup->insertSeparator();
+ popup->insertItem( tr( "MNU_EDIT_FUNC" ), this, SLOT(editFunction()));
+ }
+
+ // for all InLine, regardless isEditable() : Export to Library
+ popup->insertItem( tr( "MNU_EXPORT" ), this, SLOT( exportToLib()));
+
+ // for all InLine except EndLoop : Add Ports menu, Paste, Manage Ports
+ if ( myMain->isEditable() && type != SUPERV::EndLoopNode ) {
+ QPopupMenu* addPortMenu = new QPopupMenu(theParent);
+ addPortMenu->insertItem( tr( "MNU_INPUT" ), this, SLOT(addInputPort()));
+ if (getNodeType() != SUPERV::LoopNode)
+ addPortMenu->insertItem( tr( "MNU_OUTPUT" ), this, SLOT(addOutputPort()));
+
+ popup->insertItem( tr( "MNU_ADD_PORT" ), addPortMenu);
+ popup->insertItem( tr( "MNU_MANAGE_PORTS" ), this, SLOT(managePorts()));
+
+ // Paste Port functionality
+ int aPasteItem = popup->insertItem(tr("ITM_PASTE_PORT"), this, SLOT(pastePort()));
+ SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
+ if ( !aCB->isCopyPort() || (type == SUPERV::LoopNode && !aCB->getCopyPort()->IsInput()) )
+ popup->setItemEnabled( aPasteItem, false );
+ }
}
}
-
return popup;
}
void SUPERVGUI_CanvasNode::merge()
{
- //MESSAGE("===> SUPERVGUI_CanvasNode::merge() " << myNode->Name());
// synchronize port list
bool update = false;
isIgnore = true;
SUPERVGUI_CanvasPort* aPort;
QObjectList* aPortList = queryList("SUPERVGUI_CanvasPort");
- //cout << " get port list... " ;
SUPERV_Ports aPorts = myNode->Ports();
- //cout << aPorts->length() << endl;
for (int i = 0; i < aPorts->length(); i++) {
aPort = (SUPERVGUI_CanvasPort*)
child(myMain->getCanvas()->getPortName(aPorts[i].in()), "SUPERVGUI_CanvasPort");
if (aPort) {
- //cout << " update port " << aPort->name() << endl;
aPortList->removeRef(aPort);
aPort->update();
}
else {
- //cout << " create port " << myMain->getCanvas()->getPortName(aPorts[i].in()) << endl;
createPort(aPorts[i].in());
update = true;
}
}
- //cout << " get stream port list... " ;
SUPERV_StreamPorts aStreamPorts = myNode->StreamPorts();
- //cout << aStreamPorts->length() << endl;
for (int i = 0; i < aStreamPorts->length(); i++) {
aPort = (SUPERVGUI_CanvasPort*)
child(myMain->getCanvas()->getPortName(aStreamPorts[i].in()), "SUPERVGUI_CanvasPort");
if (aPort) {
- //cout << " update stream port " << aPort->name() << endl;
aPortList->removeRef(aPort);
aPort->update();
}
else {
- //cout << " create stream port " << myMain->getCanvas()->getPortName(aStreamPorts[i].in()) << endl;
createPort(aStreamPorts[i].in());
update = true;
}
}
- //cout << " remove inexistant " << endl;
QObjectListIt it(*aPortList);
while ((aPort=(SUPERVGUI_CanvasPort*)it.current()) != 0) {
++it;
sync(); // update node state also
}
-void SUPERVGUI_CanvasNode::sync()
-{
- //MESSAGE("===> SUPERVGUI_CanvasNode::sync() " << myNode->Name() << ", state " << myNode->State());
-
- //if myNode is a MacroNode then set it state to state of its subgraph
- if (myNode->IsMacro() && myMain->getDataflow()->IsExecuting()) {
+void SUPERVGUI_CanvasNode::sync() {
+ const bool isExecuting = myMain->getDataflow()->IsExecuting();
+ if ( myNode->IsMacro() && isExecuting ) {
// get SubGraph from MacroNode
SUPERV_Graph aMacro = SUPERV::Graph::_narrow(myNode);
if (!SUPERV_isNull(aMacro)) {
}
}
}
- else
- getPrs()->setState(myNode->State());
+ else {
+ SUPERV::GraphState aState = myNode->State();
+
+ // asv : 18.11.04 : fix for 6170 : after execution is finished, nodes' status must be reset.
+ // asv : 13.12.04 : commented out setting EditingState. See 2.21.
+ //if ( !isExecuting && myMain->IsGUIEventLoopFinished() && (aState == SUPERV::DoneState ||
+ // aState == SUPERV::KillState || aState == SUPERV::StopState ) )
+ // aState = SUPERV::EditingState;
+ getPrs()->setState(aState);
+ }
// update child ports
const QObjectList* list = children();
getPrs()->setState(theStateFromEvent);
}
-bool SUPERVGUI_CanvasNode::setNodeName(QString aName)
-{
+bool SUPERVGUI_CanvasNode::setNodeName(QString aName) {
bool result = myNode->SetName(aName.latin1());
if (result) {
setName(myNode->Name());
return result;
}
-void SUPERVGUI_CanvasNode::rename()
-{
+void SUPERVGUI_CanvasNode::rename() {
QString aName = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), myNode->Name());
if (!aName.isEmpty()) {
setNodeName(aName);
void SUPERVGUI_CanvasNode::remove() {
Trace("SUPERVGUI_CanvasNode::remove");
+ myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
+
+ //set myCopyPort from Main object to empty if engine of this port is deleted
+ //check if any port of this deleted node has been copied
+ SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
+ if ( aCB->isCopyPort() )
+ if ( QString(myNode->Name()) == QString(aCB->getCopyPort()->Node()->Name()) )
+ aCB->setCopyPort( 0 );
+
+ //set myCopyNode from Main object to empty if engine of this node is deleted
+ //check if myCopyNode and this node engine is equal
+ if ( aCB->isCopyNode() )
+ if ( QString(myNode->Name()) == QString(aCB->getCopyNode()->Name()) )
+ aCB->setCopyNode( 0 );
+
+ // mkr: since the deletion of the node allow only in CANVAS view,
+ // it is necessary to remove the CanvasArray's children, which
+ // have the same CNode engine as deleting node
+ myMain->removeArrayChild(myNode);
+
SUPERVGUI_Canvas* aCanvas = myMain->getCanvas();
setDestroyed();
myNode->destroy();
aCanvas->update();
}
+void SUPERVGUI_CanvasNode::copy() {
+ Trace("SUPERVGUI_CanvasNode::copy()");
+ SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
+ const int aKind = getNodeType();
+ if ( aKind == SUPERV::EndLoopNode || aKind == SUPERV::EndSwitchNode )
+ aCB->setCopyNode( SUPERV::CNode::_duplicate(SUPERV::GNode::_narrow(getEngine())->Coupled()) );
+ else
+ aCB->setCopyNode( SUPERV::CNode::_duplicate( getEngine() ) );
+}
+
void SUPERVGUI_CanvasNode::suspendResume() {
Trace("SUPERVGUI_CanvasNode::suspendResume");
int n = queryList("SUPERVGUI_CanvasNode")->count();
QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPENDNODE"));
} else {
syncOnEvent(SUPERV::SuspendReadyState);
- myMain->getMyThread()->stopThread(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2"));
+ myMain->getMessage()->setMessage(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2"));
}
}
}
QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_KILLNODE"));
} else {
syncOnEvent(SUPERV_Kill);
- myMain->getMyThread()->stopThread(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2"));
+ myMain->getMessage()->setMessage(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2"));
}
}
-
+/* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
+ the comment from kloss (in Main.cxx) may be explaining it, but it's in French and I do not understand it..
void SUPERVGUI_CanvasNode::stopRestart() {
Trace("SUPERVGUI_CanvasNode::stopRestart");
}
}
}
-
+*/
void SUPERVGUI_CanvasNode::changeInformation() {
SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(myNode, !myMain->isEditable());
if (aDlg->exec()) {
delete aDlg;
}
+/* asv : 13.12.04 : The functions below are not called from anywhere, so commenting them out...
void SUPERVGUI_CanvasNode::configure()
{
Trace("SUPERVGUI_CanvasNode::configure");
SUPERVGUI_Python cp(myMain->getStudy()->get_PyInterp(), !myMain->isEditable());
cp.exec();
}
+*/
bool SUPERVGUI_CanvasNode::isWarning()
{
void SUPERVGUI_CanvasNode::browse()
{
+ // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
+ //myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
if (!myBrowseDlg) {
myBrowseDlg = new SUPERVGUI_BrowseNodeDlg(this);
myBrowseDlg->installEventFilter(this);
}
SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg(getPortsNamesIN(aNode,true));
if (aDlg->exec()) {
+ myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
SUPERV_Port aPort = aNode->InPort(aDlg->getName().latin1(),
aDlg->getType().latin1());
delete aDlg;
SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg(getPortsNamesIN(aNode,false));
if (aDlg->exec()) {
+ myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
SUPERV_Port aPort = aNode->OutPort(aDlg->getName().latin1(),
aDlg->getType().latin1());
delete aDlg;
void SUPERVGUI_CanvasNode::addInputPort() {
SUPERV_Port aPort = createInPort();
- if (aPort == NULL) return;
+ if (aPort == NULL || CORBA::is_nil( aPort ) ) return;
createPort(aPort.in());
}
void SUPERVGUI_CanvasNode::addOutputPort() {
SUPERV_Port aPort = createOutPort();
- if (aPort == NULL) return;
+ if (aPort == NULL || CORBA::is_nil( aPort ) ) return;
createPort(aPort.in());
}
-void SUPERVGUI_CanvasNode::editFunction()
-{
+void SUPERVGUI_CanvasNode::editFunction() {
if (getNodeType() == SUPERV::LoopNode) {
SUPERVGUI_EditPythonDlg* aDlg = new SUPERVGUI_EditPythonDlg(true);
SUPERV_LNode aLNode = getLoopNode();
aDlg->setMoreFunction(aLNode->PyMore());
aDlg->setNextFunction(aLNode->PyNext());
if (aDlg->exec()) {
+ myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
aLNode->SetPyInit(aDlg->getInitFuncName().latin1(), (aDlg->getInitFunction()).in());
aLNode->SetPyMore(aDlg->getMoreFuncName().latin1(), (aDlg->getMoreFunction()).in());
aLNode->SetPyNext(aDlg->getNextFuncName().latin1(), (aDlg->getNextFunction()).in());
SUPERV_INode aINode = getInlineNode();
aDlg->setFunction(aINode->PyFunction());
if (aDlg->exec()) {
+ myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
aINode->SetPyFunction(aDlg->getFuncName().latin1(), (aDlg->getFunction()).in());
}
delete aDlg;
}
}
+
+/**
+ * Called on "Paste port" command of popup menu
+ */
+void SUPERVGUI_CanvasNode::pastePort() {
+ SUPERVGUI_Clipboard::getClipboard()->pastePort( this );
+}
+
+/**
+ * Called on "Edit ports" popup menu command. See SUPERVGUI_ManagePortsDlg.h
+ * for detailed description of the functionality
+ */
+void SUPERVGUI_CanvasNode::managePorts() {
+ SUPERVGUI_ManagePortsDlg* aDlg = new SUPERVGUI_ManagePortsDlg( this );
+ aDlg->exec();
+ delete aDlg;
+}
+
+/**
+ * Called on "Export to Library" popup menu command. See SUPERVGUI_Library.h
+ * for details on InLine nodes library functionality
+ */
+void SUPERVGUI_CanvasNode::exportToLib() {
+ SUPERV::INode_var anINode = SUPERV::INode::_narrow( getEngine() );
+ if ( !CORBA::is_nil( anINode ) )
+ SUPERVGUI_Library::getLibrary()->Export( anINode );
+ else
+ QAD_MessageBox::error1( QAD_Application::getDesktop(), tr( "ERROR" ), tr( "MSG_BAD_INODE" ), tr( "OK" ) );
+}