void flowwidget::mouseReleaseEvent(QMouseEvent* event) {
    this->update();
    if (!hasHeld) {
        QPointF calibLocalPos = paintTransform.inverted().map(event->localPos());
        //Click - find on what
        if (SelectedGUID == "") {
            //Selected a node
            std::for_each(XMLHandlr->OrphanNodes.begin(), XMLHandlr->OrphanNodes.end(),
                          [&](std::pair<std::string, FlowNode> nodepair) {
                QFont basefont = QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult);
                QFont titlefont = QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult*1.5);
                NodeSize ns = getNodeSize(basefont, titlefont, nodepair.second);

                if (((nodepair.second.CenterPosX - (ns.Width/2)) < calibLocalPos.x()) &&
                        ((nodepair.second.CenterPosY - (ns.Height/2)) < calibLocalPos.y()) &&
                        ((nodepair.second.CenterPosX + (ns.Width/2)) > calibLocalPos.x()) &&
                        ((nodepair.second.CenterPosY + (ns.Height/2)) > calibLocalPos.y())) {
                    //Correct node found
                    SelectedGUID = nodepair.second.GUID;
                }
            });
            if (SelectedGUID == "")
                std::cerr << "[FlowWidget-MouseCtrl] Couldn't find a node, sorry :(" << std::endl;
        }
    }
    dragState = MouseDragState::PAN;
}
void flowwidget::mousePressEvent(QMouseEvent* event) {
    previousMouseMove = event->localPos();
    hasHeld = false;
    std::cerr << "[FlowWidget-MouseCtrl] Detected mouse press on behalf of " << ((SelectedGUID != "")?SelectedGUID:"no one") << "." << std::endl;
    if (SelectedGUID != "") {
        QPointF calibLocalPos = paintTransform.inverted().map(event->localPos());
        //A node is selected already
        FlowNode fn = XMLHandlr->OrphanNodes[SelectedGUID];
        QFont basefont = QFont("sans-serif", BaseFontSize*fn.FontSizeMult);
        QFont titlefont = QFont("sans-serif", BaseFontSize*fn.FontSizeMult*1.5);
        NodeSize ns = getNodeSize(basefont, titlefont, fn);

        int MoveButtonXOrigin = fn.CenterPosX + (ns.Width/2) - GripWidth/2;
        int MoveButtonYOrigin = fn.CenterPosY - (ns.Height/2) - GripWidth/2;
        if ((MoveButtonXOrigin < calibLocalPos.x()) &&
                (MoveButtonYOrigin < calibLocalPos.y()) &&
                (MoveButtonXOrigin + GripWidth > calibLocalPos.x()) &&
                (MoveButtonYOrigin + GripWidth > calibLocalPos.y())) {
            // Hit the node move button
            dragState = MouseDragState::MOVE_NODE;
            std::cerr << "[FlowWidget-MouseCtrl] Hit move button, set Drag State to MOVE_NODE." << std::endl;
        } else {
            //Deselect node
            SelectedGUID = "";
        }
    }
}
void flowwidget::SaveSVG(std::ostream &data) {
    std::cerr << "[FlowWidget] Request to export recieved, enumerating nodes for size" << std::endl;
    int GenMinimum = INT_MAX;
    int GenExtreme = INT_MIN;
    std::for_each(XMLHandlr->OrphanNodes.begin(), XMLHandlr->OrphanNodes.end(),
                  [&](std::pair<std::string, FlowNode> nodepair) {
        NodeSize ns = getNodeSize(QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult), QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult*1.5), nodepair.second);

        if (nodepair.second.CenterPosX - (ns.Width/2) < GenMinimum)
            GenMinimum = nodepair.second.CenterPosX - (ns.Width/2);
        if (nodepair.second.CenterPosY - (ns.Height/2) < GenMinimum)
            GenMinimum = nodepair.second.CenterPosY - (ns.Height/2);
        if (nodepair.second.CenterPosX + (ns.Width/2) > GenExtreme)
            GenExtreme = nodepair.second.CenterPosX + (ns.Width/2);
        if (nodepair.second.CenterPosY + (ns.Height/2) > GenExtreme)
            GenExtreme = nodepair.second.CenterPosY + (ns.Height/2);
    });
    int SVGSize = GenExtreme-GenMinimum;
    std::cerr << "[FlowWidget] Calculated sheet size of " << SVGSize << std::endl;

    QSvgGenerator svgen;
    QIODevice* iodev = new IOStreamBridge(data);
    svgen.setOutputDevice(iodev);
    svgen.setSize(QSize(SVGSize, SVGSize));
    renderFullTree(&svgen, XMLHandlr,
                   LineColor, BaseFontSize, "",
                   SVGSize, SVGSize, PermaScale, 1, 0, 0);
    data.flush();
    std::cerr << "[FlowWidget] Finished export!" << std::endl;
}
void flowwidget::LoadXML(std::istream &data) {
    QXmlSimpleReader qxsr;
    qxsr.setContentHandler(XMLHandlr);
    qxsr.setErrorHandler(XMLHandlr);

    QIODevice* iodev = new IOStreamBridge(data);
    if (qxsr.parse(QXmlInputSource(iodev))) {
        std::cerr << "[FlowWidget] Recentering nodes and adjusting scale." << std::endl;
        double GenMinimumX = std::numeric_limits<double>::max();
        double GenExtremeX = std::numeric_limits<double>::min();
        double GenMinimumY = std::numeric_limits<double>::max();
        double GenExtremeY = std::numeric_limits<double>::min();
        std::for_each(XMLHandlr->OrphanNodes.begin(), XMLHandlr->OrphanNodes.end(),
                      [&](std::pair<std::string, FlowNode> nodepair) {
            NodeSize ns = getNodeSize(QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult), QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult*1.5), nodepair.second);
            if (nodepair.second.CenterPosX - double(ns.Width/2) < GenMinimumX)
                GenMinimumX = nodepair.second.CenterPosX - double(ns.Width/2);
            if (nodepair.second.CenterPosX + double(ns.Width/2) > GenExtremeX)
                GenExtremeX = nodepair.second.CenterPosX + double(ns.Width/2);
            if (nodepair.second.CenterPosY - double(ns.Height/2) < GenMinimumY)
                GenMinimumY = nodepair.second.CenterPosY - double(ns.Height/2);
            if (nodepair.second.CenterPosY + double(ns.Height/2) > GenExtremeY)
                GenExtremeY = nodepair.second.CenterPosY + double(ns.Height/2);
        });

        QLineF XLine(QPointF(GenMinimumX, 0), QPointF(GenExtremeX, 0));
        QLineF YLine(QPointF(GenMinimumY, 0), QPointF(GenExtremeY, 0));
        if (XLine.length() > YLine.length()) {
            PermaScale = 1.0/XLine.length();
        } else {
            PermaScale = 1.0/YLine.length();
        }

        double NewCenterX = (GenMinimumX + GenExtremeX) / 2.0;
        double NewCenterY = (GenMinimumY + GenExtremeY) / 2.0;
        std::cerr << "[FlowWidget] Nodes are off by X " << -NewCenterX << ", Y " << -NewCenterY <<
                     ", deducted from XMin " << GenMinimumX << ", XMax " << GenExtremeX <<
                     ", YMin " << GenMinimumY << ", YMax" << GenExtremeY << std::endl;
        for (auto itr = XMLHandlr->OrphanNodes.begin(); itr != XMLHandlr->OrphanNodes.end(); itr++) {
            itr->second.CenterPosX -= NewCenterX;
            itr->second.CenterPosY -= NewCenterY;
        }
        std::cerr << "[FlowWidget] Recentered nodes. Ready!" << std::endl;
    } else {
        std::cerr << "[FlowWidget] Error loading XML." << std::endl;
    }
}
void NodeControl::initControl()
{
	setSize(getNodeSize());

	if(node)
	{
		std::vector<GuiElement*> children;
		//Label (node name)
		nodeName = new Label(this, APoint(), DEFAULT_STATE_FLOAT, node->getName(), 12);
		nodeName->centerAround(size*(1.0f/2.0f));
		children.push_back(nodeName);

		bool hasConnector[static_cast<unsigned int>(NCType::COUNT)] {false};

		std::vector<NodeConnector*> c = node->getConnectors();

		for(auto con : c)
			hasConnector[toIndex(con->ioType)] = true;

		//Create connectors
		for(unsigned int i = 0; i < toIndex(NCType::COUNT); i++)
		{
			if(hasConnector[i])
			{
				connectorControls[i] = new NodeConnectorControl(this, static_cast<NCType>(i));
				//children.push_back(connectorControls[i]);
			}
		}
		
		//init(&children, nullptr);
	}
	else
	{
		std::cout << "ERRORRRR --> NodeControl's node is null!\n";
	}
	
	//TODO: Separate this for each node type
	setBgStateColor(Color(0.2f, 0.2f, 0.2f, 1.0f), CS::NONE);
	setBgStateColor(Color(0.3f, 0.3f, 0.3f, 1.0f), CS::HOVERING);
	setBgStateColor(Color(0.05f, 0.05f, 0.05f, 1.0f), CS::CLICKING);
	setBgStateColor(Color(0.05f, 0.05f, 0.05f, 1.0f), CS::DRAGGING);
}
Exemple #6
0
  int DA::computeLocalToGlobalMappings() {
    DendroIntL localNodeSize = getNodeSize();
    DendroIntL off1, globalOffset;
    MPI_Request sendRequest;
    MPI_Status status;
    if(m_bIamActive) {
      par::Mpi_Scan<DendroIntL>(&localNodeSize, &off1, 1, MPI_SUM, m_mpiCommActive); 
      if(m_iRankActive < (m_iNpesActive-1)) {
        par::Mpi_Issend<DendroIntL>(&off1, 1, m_iRankActive+1, 0, m_mpiCommActive, &sendRequest);
      }

      if(m_iRankActive) {
        par::Mpi_Recv<DendroIntL>(&globalOffset, 1, m_iRankActive-1, 0, m_mpiCommActive, &status);
      }else {
        globalOffset = 0;
      }
    }

    std::vector<DendroIntL> gNumNonGhostNodes(localNodeSize); 
    for(DendroIntL i = 0; i < localNodeSize; i++) {
      gNumNonGhostNodes[i] = (i+globalOffset);   
    }

    vecGetBuffer<DendroIntL>(gNumNonGhostNodes, m_dilpLocalToGlobal,
        false, false, true, 1);

    if(m_bIamActive && (m_iRankActive < (m_iNpesActive-1))) {
      MPI_Status statusWait;
      MPI_Wait(&sendRequest, &statusWait);
    }

    ReadFromGhostsBegin<DendroIntL>(m_dilpLocalToGlobal,1);
    ReadFromGhostsEnd<DendroIntL>(m_dilpLocalToGlobal);

    gNumNonGhostNodes.clear();
    m_bComputedLocalToGlobal = true;

    return 0;
  }//end function
void renderFullTree(QPaintDevice *paintdev, SketchXMLHandler* XMLHandlr,
                    QColor LineColor, std::uint16_t BaseFontSize, std::string SelectedGUID,
                    double Width, double Height, double PermaScale, double ScaleFactor, double PanX, double PanY,
                    QTransform *paintTransform = nullptr) {
    QPainter paint(paintdev);
    paint.resetTransform();
    paint.translate(double(Width/2) + (PanX * ScaleFactor), double(Height/2) + (PanY * ScaleFactor));
    paint.scale(PermaScale * Width * ScaleFactor, PermaScale * Width * ScaleFactor);
    if (paintTransform != nullptr)
        *paintTransform = paint.worldTransform();
    paint.setRenderHint(QPainter::Antialiasing, true);
    paint.setRenderHint(QPainter::TextAntialiasing, true);
    paint.setRenderHint(QPainter::SmoothPixmapTransform, true);

    QPen linepen (LineColor);
    linepen.setWidth(5);
    paint.setPen(linepen);
    std::for_each(XMLHandlr->nodelinkmap.begin(), XMLHandlr->nodelinkmap.end(),
                  [&](std::pair<std::string, std::vector<std::string>> block) {
        FlowNode fnparent = XMLHandlr->OrphanNodes[block.first];
        std::for_each(block.second.begin(), block.second.end(), [&](std::string child) {
            FlowNode fnchild = XMLHandlr->OrphanNodes[child];
            if ((fnchild.Type == NodeType::NONE) || (fnparent.Type == NodeType::NONE))
                return;
            paint.drawLine(fnparent.CenterPosX, fnparent.CenterPosY,
                           fnchild.CenterPosX, fnchild.CenterPosY);
        });
    });

    std::for_each(XMLHandlr->OrphanNodes.begin(), XMLHandlr->OrphanNodes.end(),
                  [&](std::pair<std::string, FlowNode> nodepair) {
        if (nodepair.second.Type == NodeType::NONE)
            return;
        QFont basefont = QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult);
        QFont titlefont = QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult*1.5);

        NodeSize ns = getNodeSize(basefont, titlefont, nodepair.second);

        int rectoriginx = nodepair.second.CenterPosX - (ns.Width/2);
        int rectoriginy = nodepair.second.CenterPosY - (ns.Height/2);

        QColor PrimColor = QColor(nodepair.second.ColorRGBA[0],
                nodepair.second.ColorRGBA[1],
                nodepair.second.ColorRGBA[2],
                nodepair.second.ColorRGBA[3]);
        paint.fillRect(rectoriginx, rectoriginy, ns.Width, ns.Height, PrimColor);

        QColor SecColor;
        if (PrimColor.toHsl().lightness() > 256)
            SecColor = PrimColor.lighter(200);
        else
            SecColor = PrimColor.darker(300);
        QPen textpen (SecColor);
        textpen.setWidth(3);
        paint.setPen(textpen);
        paint.drawRect(rectoriginx, rectoriginy, ns.Width, ns.Height);

        paint.setFont(titlefont);
        paint.drawText(rectoriginx + BlockPadding, rectoriginy + BlockPadding,
                       ns.Width - (BlockPadding*2), ns.TitleBoundBox.height(),
                       Qt::AlignCenter, QString(nodepair.second.Title.c_str()));
        paint.setFont(basefont);
        paint.drawText(nodepair.second.CenterPosX - (ns.DescBoundBox.width()/2),
                       rectoriginy + BlockPadding + ns.TitleBoundBox.height() + BlockPadding,
                       ns.DescBoundBox.width(), ns.DescBoundBox.height(),
                       Qt::AlignCenter | Qt::TextWordWrap,
                       QString(nodepair.second.Desc.c_str()));

        if (nodepair.second.GUID == SelectedGUID) {
            //Edge blocks
            paint.fillRect(rectoriginx + ns.Width - GripWidth/2, rectoriginy - GripWidth/2,
                           GripWidth, GripWidth,
                           Qt::black);
            paint.fillRect(rectoriginx + ns.Width + 2 - GripWidth/2, rectoriginy + 2 - GripWidth/2,
                           GripWidth-4, GripWidth-4,
                           Qt::white);
        }
    });
    paint.end();
}