]> Creatis software - cpPlugins.git/commitdiff
Editor finished
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 15 Jan 2016 14:57:21 +0000 (09:57 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 15 Jan 2016 14:57:21 +0000 (09:57 -0500)
lib/cpPipelineEditor/Block.cxx
lib/cpPipelineEditor/Canvas.cxx
lib/cpPipelineEditor/Editor.cxx
lib/cpPipelineEditor/Editor.h
lib/cpPlugins/Interface/Workspace.cxx
lib/cpPlugins/Interface/Workspace.h
lib/cpPlugins/Interface/WorkspaceIO.cxx

index 96e60f8c3d2698c6cca5edc6d8b80f1dfe775f55..6d473efba274ba4f78e6ca396a44aeb3e868e46d 100644 (file)
@@ -233,17 +233,6 @@ _configPort( Port* port )
       i->setPos( -this->m_Width / 2 - 2 * port->radius( ), y );\r
     else if( dynamic_cast< OutputPort* >( i ) != NULL )\r
       i->setPos( this->m_Width / 2, y );\r
-\r
-    /* TODO\r
-       Port* p = dynamic_cast< Port* >( i );\r
-       if( p == NULL )\r
-       continue;\r
-\r
-       if( dynamic_cast< OutputPort* >( p ) != NULL )\r
-       p->setPos( this->m_Width / 2 + port->radius( ), y );\r
-       else\r
-       p->setPos( -this->m_Width / 2 - port->radius( ), y );\r
-    */\r
     y += h;\r
 \r
   } // rof\r
index a5fcc3f7448c31e8e2e0525d28deebd404feb6d4..29897fbd163d299bd7cf4761b50c238ce43587de 100644 (file)
@@ -44,20 +44,6 @@ editor( ) const
   return( this->m_Editor );
 }
 
-// -------------------------------------------------------------------------
-/* TODO
-   void cpPipelineEditor::Canvas::
-   keyPressEvent( QKeyEvent* event )
-   {
-   }
-
-   // -------------------------------------------------------------------------
-   void cpPipelineEditor::Canvas::
-   timerEvent( QTimerEvent* event )
-   {
-   }
-*/
-
 // -------------------------------------------------------------------------
 void cpPipelineEditor::Canvas::
 wheelEvent( QWheelEvent* event )
@@ -121,217 +107,4 @@ _scaleView( qreal scaleFactor )
   this->scale( scaleFactor, scaleFactor );
 }
 
-// -------------------------------------------------------------------------
-  /*
-void cpPipelineEditor::Canvas::
-_createBlock( TFilter* f )
-{
-  if( f == NULL )
-    return;
-
-  // Add block
-  Block* b = new Block( 0, this->scene( ) );
-  b->addPort( f->GetName( ), 0, Port::NamePort );
-  b->addPort( f->GetClassName( ).c_str( ), 0, Port::TypePort );
-
-  // Add input ports
-  std::set< std::string > inputs;
-  f->GetInputsNames( inputs );
-  for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
-    b->addInputPort( iIt->c_str( ) );
-  //in_ports[ vIt->first ][ *iIt ] = b->addInputPort( iIt->c_str( ) );
-
-  // Add output ports
-  std::set< std::string > outputs;
-  f->GetOutputsNames( outputs );
-  for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
-    b->addOutputPort( oIt->c_str( ) );
-  // out_ports[ vIt->first ][ *oIt ] = b->addOutputPort( oIt->c_str( ) );
-
-  // Keep a trace of this visual graph
-  this->m_Graph->InsertVertex( f->GetName( ), b );
-
-  // Add vertices and keep track of ports
-    std::map< std::string, std::map< std::string, Port* > >
-    in_ports, out_ports;
-    auto vIt = this->m_Workspace->GetGraph( )->BeginVertices( );
-    auto vIt_end = this->m_Workspace->GetGraph( )->EndVertices( );
-    for( ; vIt != vIt_end; ++vIt )
-    {
-    // Add block
-    Block* b = new Block( 0, scene );
-    b->addPort( vIt->second->GetName( ), 0, Port::NamePort );
-    b->addPort( vIt->second->GetClassName( ).c_str( ), 0, Port::TypePort );
-
-    // Get filter
-    auto f = dynamic_cast< TFilter* >( vIt->second.GetPointer( ) );
-    if( f == NULL )
-    continue;
-
-    // Add input ports
-    std::set< std::string > inputs;
-    f->GetInputsNames( inputs );
-    for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
-    in_ports[ vIt->first ][ *iIt ] = b->addInputPort( iIt->c_str( ) );
-
-    // Add output ports
-    std::set< std::string > outputs;
-    f->GetOutputsNames( outputs );
-    for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
-    out_ports[ vIt->first ][ *oIt ] = b->addOutputPort( oIt->c_str( ) );
-
-    // Keep a trace of this visual graph
-    this->m_Graph->InsertVertex( vIt->first, b );
-
-    } // rof
-}
-  */
-
 // eof - $RCSfile$
-
-
-/*
-
-// -------------------------------------------------------------------------
-void GraphWidget::
-draw( )
-{
-  if( this->m_Workspace == NULL )
-    return;
-}
-
-// -------------------------------------------------------------------------
-void GraphWidget::itemMoved()
-{
-  if (!timerId)
-    timerId = startTimer(1000 / 25);
-}
-
-void GraphWidget::keyPressEvent(QKeyEvent *event)
-{
-  switch (event->key()) {
-  case Qt::Key_Up:
-    centerNode->moveBy(0, -20);
-    break;
-  case Qt::Key_Down:
-    centerNode->moveBy(0, 20);
-    break;
-  case Qt::Key_Left:
-    centerNode->moveBy(-20, 0);
-    break;
-  case Qt::Key_Right:
-    centerNode->moveBy(20, 0);
-    break;
-  case Qt::Key_Plus:
-    zoomIn();
-    break;
-  case Qt::Key_Minus:
-    zoomOut();
-    break;
-  case Qt::Key_Space:
-  case Qt::Key_Enter:
-    shuffle();
-    break;
-  default:
-    QGraphicsView::keyPressEvent(event);
-  }
-}
-
-void GraphWidget::timerEvent(QTimerEvent *event)
-{
-  Q_UNUSED(event);
-
-  QList<Node *> nodes;
-  foreach (QGraphicsItem *item, scene()->items()) {
-    if (Node *node = qgraphicsitem_cast<Node *>(item))
-      nodes << node;
-  }
-
-  foreach (Node *node, nodes)
-    node->calculateForces();
-
-  bool itemsMoved = false;
-  foreach (Node *node, nodes) {
-    if (node->advance())
-      itemsMoved = true;
-  }
-
-  if (!itemsMoved) {
-    killTimer(timerId);
-    timerId = 0;
-  }
-}
-
-void GraphWidget::wheelEvent(QWheelEvent *event)
-{
-  scaleView(pow((double)2, -event->delta() / 240.0));
-}
-
-void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
-{
-  //Q_UNUSED(rect);
-
-  // Shadow
-  QRectF sceneRect = rect;//this->sceneRect();
-  QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
-  QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
-  if (rightShadow.intersects(rect) || rightShadow.contains(rect))
-    painter->fillRect(rightShadow, Qt::darkGray);
-  if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
-    painter->fillRect(bottomShadow, Qt::darkGray);
-
-  // Fill
-  QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
-  gradient.setColorAt(0, Qt::white);
-  gradient.setColorAt(1, Qt::lightGray);
-  painter->fillRect(rect.intersect(sceneRect), gradient);
-  painter->setBrush(Qt::NoBrush);
-  painter->drawRect(sceneRect);
-
-#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)
-  // Text
-  QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
-                  sceneRect.width() - 4, sceneRect.height() - 4);
-  QString message(tr("Click and drag the nodes around, and zoom with the mouse "
-                     "wheel or the '+' and '-' keys"));
-
-  QFont font = painter->font();
-  font.setBold(true);
-  font.setPointSize(14);
-  painter->setFont(font);
-  painter->setPen(Qt::lightGray);
-  painter->drawText(textRect.translated(2, 2), message);
-  painter->setPen(Qt::black);
-  painter->drawText(textRect, message);
-#endif
-}
-
-void GraphWidget::scaleView(qreal scaleFactor)
-{
-  qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
-  if (factor < 0.07 || factor > 100)
-    return;
-
-  scale(scaleFactor, scaleFactor);
-}
-
-void GraphWidget::shuffle()
-{
-  foreach (QGraphicsItem *item, scene()->items()) {
-    if (qgraphicsitem_cast<Node *>(item))
-      item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
-  }
-}
-
-void GraphWidget::zoomIn()
-{
-  scaleView(qreal(1.2));
-}
-
-void GraphWidget::zoomOut()
-{
-  scaleView(1 / qreal(1.2));
-}
-
-
-*/
index 237bb5815cb76af3a14b05dbca88498be9083c72..9ab6b35537b5af476da1c5c4ed7a7b68ad607fa7 100644 (file)
@@ -148,18 +148,59 @@ itemAt( const QPointF& pos )
 }\r
 \r
 // -------------------------------------------------------------------------\r
-void cpPipelineEditor::Editor::\r
+cpPipelineEditor::Block* cpPipelineEditor::Editor::\r
 _createBlock( TFilter* f, const QPointF& pnt )\r
 {\r
   if( f == NULL )\r
-    return;\r
+    return( NULL );\r
 \r
   // Add block\r
   Block* b = new Block( f, 0, this->m_Scene );\r
   b->setPos( pnt );\r
 \r
+  // Mark exposed inputs\r
+  auto& e_in = this->m_Workspace->GetExposedInputPorts( );\r
+  std::set< std::string > f_in;\r
+  f->GetInputsNames( f_in );\r
+  for( auto iIt = f_in.begin( ); iIt != f_in.end( ); ++iIt )\r
+  {\r
+    auto eIt = e_in.begin( );\r
+    auto fIt = e_in.end( );\r
+    for( ; eIt != e_in.end( ) && fIt == e_in.end( ); ++eIt )\r
+      if( eIt->second.second == *iIt )\r
+        fIt = eIt;\r
+    if( fIt == e_in.end( ) )\r
+      continue;\r
+    \r
+    auto port = b->inputPort( iIt->c_str( ) );\r
+    port->setExtendedName( fIt->first.c_str( ) );\r
+    port->setExtend( true );\r
+\r
+  } // rof\r
+\r
+  // Mark exposed outputs\r
+  auto& e_out = this->m_Workspace->GetExposedOutputPorts( );\r
+  std::set< std::string > f_out;\r
+  f->GetOutputsNames( f_out );\r
+  for( auto iIt = f_out.begin( ); iIt != f_out.end( ); ++iIt )\r
+  {\r
+    auto eIt = e_out.begin( );\r
+    auto fIt = e_out.end( );\r
+    for( ; eIt != e_out.end( ) && fIt == e_out.end( ); ++eIt )\r
+      if( eIt->second.second == *iIt )\r
+        fIt = eIt;\r
+    if( fIt == e_out.end( ) )\r
+      continue;\r
+    \r
+    auto port = b->outputPort( iIt->c_str( ) );\r
+    port->setExtendedName( fIt->first.c_str( ) );\r
+    port->setExtend( true );\r
+\r
+  } // rof\r
+\r
   // Keep a trace of this visual graph\r
   this->m_Graph->SetVertex( f->GetName( ), b );\r
+  return( b );\r
 }\r
 \r
 // -------------------------------------------------------------------------\r
index 51c87688cb7555093b3f5c06a5f993a337063e80..f7a2615027a7e60c63f8b06dd75d8f2231b80dfd 100644 (file)
@@ -64,7 +64,7 @@ namespace cpPipelineEditor
   private:\r
     QGraphicsItem* itemAt( const QPointF& pos );\r
 \r
-    inline void _createBlock( TFilter* f, const QPointF& pnt );\r
+    inline Block* _createBlock( TFilter* f, const QPointF& pnt );\r
 \r
   protected:\r
     typedef QGraphicsSceneDragDropEvent QGraphicsSceneDragEnterEvent;\r
index be724acf5f186989cb7ccbbf7a3e518375a4f309..022f9faa0babc181feed2ff42cce0468cb5cbcd2 100644 (file)
@@ -276,6 +276,22 @@ RenameExposedOutputPort(
     return( false );
 }
 
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TExposedPorts& cpPlugins::Interface::Workspace::
+GetExposedInputPorts( ) const
+{
+  return( this->m_ExposedInputPorts );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TExposedPorts& cpPlugins::Interface::Workspace::
+GetExposedOutputPorts( ) const
+{
+  return( this->m_ExposedOutputPorts );
+}
+
 // -------------------------------------------------------------------------
 /* TODO
 cpPlugins::Interface::Workspace::
index 1f2fadaeb4393b5911ef4e8ca269f33c72b5627c..92315d71fb8c0116b45d1c4199584fbccc425f01 100644 (file)
@@ -102,6 +102,9 @@ namespace cpPlugins
         const std::string& new_name
         );
 
+      const TExposedPorts& GetExposedInputPorts( ) const;
+      const TExposedPorts& GetExposedOutputPorts( ) const;
+
       TData* GetExposedInput( const std::string& name );
       const TData* GetExposedInput( const std::string& name ) const;
       TData* GetExposedOutput( const std::string& name );
index 1d0ea81e0b05582aad6fe32dcfa837ad99be8958..dcf6c6852f17af9a26f509d494d1bf852ebcac0a 100644 (file)
@@ -77,12 +77,11 @@ LoadWorkspace( const std::string& fname )
       port->Attribute( "filter" ),
       port->Attribute( "filter_port_name" )
       );
-    port = connection->NextSiblingElement( "exposed_input_port" );
+    port = port->NextSiblingElement( "exposed_input_port" );
 
   } // elihw
 
   // Read exposed outputs
-#error ACA VOY
   port = root->FirstChildElement( "exposed_output_port" );
   while( port != NULL )
   {
@@ -91,7 +90,7 @@ LoadWorkspace( const std::string& fname )
       port->Attribute( "filter" ),
       port->Attribute( "filter_port_name" )
       );
-    port = connection->NextSiblingElement( "exposed_output_port" );
+    port = port->NextSiblingElement( "exposed_output_port" );
 
   } // elihw