2 // File : SUPERVGraph_Graph.cxx
3 // Created : 17 / 10 / 2001
4 // Author : Francis KLOSS
6 // Module : SUPERVGraph
7 // Copyright : Open CASCADE
9 #include "SUPERVGraph_Graph.h"
11 #include "QAD_Settings.h"
12 #include "QAD_Config.h"
14 #include <qcolordialog.h>
15 #include <qpopupmenu.h>
18 SUPERVGraph_Graph::SUPERVGraph_Graph(QWidget* parent) :
22 installEventFilter(viewport());
23 // viewport()->setBackgroundColor(QColor(165, 255, 176));
25 connect(this, SIGNAL(contentsMoving(int, int)), this, SLOT(Draw(int, int)));
27 popup = new QPopupMenu(viewport());
28 // if (main->isModify()) {
29 // pan = popup->insertItem("Add Node", main, SLOT(addNode()));
30 // pap = popup->insertItem("Add Point", this, SLOT(addPoint()));
31 // pdl = popup->insertItem("Delete Link", this, SLOT(deleteLink()));
32 // pif = popup->insertItem("Insert File", main, SLOT(insertFile()));
33 // pci = popup->insertItem("Change Informations", this, SLOT(changeInformation()));
34 // popup->insertSeparator();
36 // popup->insertItem("Add in Study", main, SLOT(addStudy()));
37 // popup->insertItem("Show Informations", this, SLOT(showInformation()));
38 // popup->insertSeparator();
39 // popup->insertItem("Copy (Read Only)", main, SLOT(copyReading()));
40 // popup->insertItem("Copy (Modifiying)", main, SLOT(copyModifying()));
43 void SUPERVGraph_Graph::sync() {
44 // bool editing = main->getDataflow()->IsEditing();
45 // if (main->isModify()) {
46 // popup->setItemEnabled(pci, editing);
47 // popup->setItemEnabled(pan, editing);
48 // popup->setItemEnabled(pap, editing);
49 // popup->setItemEnabled(pdl, editing);
50 // popup->setItemEnabled(pif, editing);
53 // SUPERVGraph_Node* ihmNode;
54 // QObjectList* ihmList = queryList("SUPERVGraph_Node");
55 // SUPERV_Nodes nodes = main->getDataflow()->Nodes();
56 // int n = nodes->length();
58 // for (int i=0; i<n; i++) {
59 // ihmNode = (SUPERVGraph_Node *)child(nodes[i]->Name(), "SUPERVGraph_Node");
60 // if (ihmNode == NULL) {
61 // ihmNode = new SUPERVGraph_Node(viewport(), main, nodes[i]);
62 // addChild(ihmNode, nodes[i]->X(), nodes[i]->Y());
64 // moveChild(ihmNode, nodes[i]->X(), nodes[i]->Y());
65 // ihmList->removeRef(ihmNode);
70 // QObjectListIt i(*ihmList);
71 // while ((ihmNode=(SUPERVGraph_Node*)i.current()) != 0) {
77 // SUPERVGraph_PortIn* pi;
78 // ihmList = queryList("SUPERVGraph_PortIn");
80 // while ((pi=(SUPERVGraph_PortIn*)i.current()) != 0) {
86 // SUPERVGraph_PortOut* po;
87 // ihmList = queryList("SUPERVGraph_PortOut");
89 // while ((po=(SUPERVGraph_PortOut*)i.current()) != 0) {
98 SUPERVGraph_Graph::~SUPERVGraph_Graph() {
101 bool SUPERVGraph_Graph::eventFilter(QObject* object, QEvent* event) {
102 if ((event->type() == QEvent::Move ) ||
103 (event->type() == QEvent::Paint) ||
104 (event->type() == QEvent::Resize) ) {
107 return(QScrollView::eventFilter(object, event));
110 void SUPERVGraph_Graph::Draw(int x, int y) {
111 QPainter p(viewport());
112 p.eraseRect(viewport()->rect());
113 p.setPen(QPen(Qt::black, 2));
115 // SUPERVGraph_Point* c;
116 // SUPERVGraph_Point* n;
117 // QObjectList* points = queryList("SUPERVGraph_Point");
118 // QObjectListIt i(*points);
119 // while ((c=(SUPERVGraph_Point*)i.current()) != 0) {
123 // p.drawLine(contentsToViewport(QPoint(c->getX()+POINT_SIZE_HALF, c->getY()+POINT_SIZE_HALF)),
124 // contentsToViewport(QPoint(n->getX()+POINT_SIZE_HALF, n->getY()+POINT_SIZE_HALF)) );
130 void SUPERVGraph_Graph::contentsMousePressEvent(QMouseEvent* e) {
131 where = viewportToContents(viewport()->mapFromGlobal(e->globalPos()));
132 // main->showPopup(popup, e);
135 void SUPERVGraph_Graph::contentsMouseReleaseEvent(QMouseEvent* e) {
136 // main->sketchPoint(NULL);
138 if ( e->button() == Qt::RightButton ) {
139 QPopupMenu* popup = createPopup();
141 popup->exec( QCursor::pos() );
149 void SUPERVGraph_Graph::contentsMouseMoveEvent(QMouseEvent* e) {
150 // main->sketchMove();
153 float SUPERVGraph_Graph::distance(int xp, int yp, int xl, int yl, int xn, int yn) {
157 float px = (float)(xp);
158 float py = (float)(yp);
159 float lx = (float)(xl);
160 float ly = (float)(yl);
161 float nx = (float)(xn);
162 float ny = (float)(yn);
192 QPoint SUPERVGraph_Graph::getPoint() {
196 // SUPERVGraph_Point* SUPERVGraph_Graph::findPoint(int x, int y) {
198 // float d = SCROLL_MAX;
199 // SUPERVGraph_Point* t = NULL;
200 // SUPERVGraph_Point* c;
201 // SUPERVGraph_Point* n;
202 // QObjectList* points = queryList("SUPERVGraph_Point");
203 // QObjectListIt i(*points);
205 // while ((c=(SUPERVGraph_Point*)i.current()) != 0) {
209 // m = distance(x, y, c->getX(), c->getY(), n->getX(), n->getY());
220 void SUPERVGraph_Graph::addPoint() {
221 // int x = where.x();
222 // int y = where.y();
223 // SUPERVGraph_Point* p = findPoint(x, y);
225 // QMessageBox::warning(0, "Supervision Error", "No Link to Add a Point");
227 // p->addPoint(x, y, true);
231 void SUPERVGraph_Graph::deleteLink() {
232 // SUPERVGraph_Point* p = findPoint(where.x(), where.y());
234 // QMessageBox::warning(0, "Supervision Error", "No Link to Delete");
236 // SUPERV_Link l = p->getLink();
238 // QMessageBox::warning(0, "Supervision Error", "No Link to Delete");
246 void SUPERVGraph_Graph::showInformation() {
247 // if (Supervision.information(Engines::Node::_narrow(main->getDataflow()), false)) {
252 void SUPERVGraph_Graph::changeInformation() {
253 // if (Supervision.information(Engines::Node::_narrow(main->getDataflow()), true)) {
261 void SUPERVGraph_Graph::onCreatePopup()
264 // if (myPopup->count()<1) {
265 if ( myPopup->count() > 0 )
266 myIDs.append ( myPopup->insertSeparator() );
268 myIDs.append ( id = myPopup->insertItem (tr ("MEN_VP3D_CHANGEBGR")) );
269 QAD_ASSERT ( myPopup->connectItem ( id, this, SLOT(onChangeBackgroundColor())) );
274 void SUPERVGraph_Graph::onChangeBackgroundColor()
276 QColor previousColor = viewport()->backgroundColor();
277 QColor selColor = QColorDialog::getColor ( previousColor, NULL );
278 if ( selColor.isValid() )
279 viewport()->setBackgroundColor( selColor );
281 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorRed", selColor.red() );
282 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorGreen", selColor.green() );
283 QAD_CONFIG->addSetting( "SUPERVGraph:BackgroundColorBlue", selColor.blue() );