示例#1
0
ArrowModel::ArrowModel(ApplicationWindow* parentWnd,
                       Glib::RefPtr<PortModel> src, Glib::RefPtr<PortModel> dest,
                       Connection* con, ApplicationModel* appModel, bool nullArw): PolylineModel(0,0,0,0), connection(NULL, NULL) 
{
    parentWindow = parentWnd;
    source = src;
    destination = dest;
    selected = false;
    bExist = false;
    bNullArrow = nullArw;
    applicationModel = appModel; 
    bNested = (applicationModel != NULL);
    if(appModel)
        application = appModel->getApplication();
    else        
        application = parentWindow->manager.getKnowledgeBase()->getApplication();

    if(con)
    {
        strLabel = con->carrier();
        connection = *con;
    }
        
    this->property_close_path().set_value(false);
    this->property_line_width().set_value(ARROW_LINEWIDTH);
    this->property_arrow_width().set_value(5.0);
    if(!bNullArrow)
        this->property_end_arrow().set_value(true);
    if(bNested)
    {
        defaultColor = "#555555";
        //GooCanvasLineDash *dash = goo_canvas_line_dash_new (ARROW_LINEWIDTH, 3.0, 3.0);
        //g_object_set(this->gobj(), "line-dash", dash, NULL);
    }
    else
        defaultColor = "black";

    source->addSourceArrow(this);
    destination->addDestinationArrow(this);
    if(!bNullArrow)
    {
        string strCarrier = strLabel;
        string dummyLabel;
        //Adding connection 
        if(application)
        {
            string strFrom, strTo;
            Glib::RefPtr<InternalPortModel> intPort;
            Glib::RefPtr<ExternalPortModel> extPort;
            Glib::RefPtr<PortArbitratorModel> arbPort;
            Module* module;
            InputData* input = NULL;
            OutputData* output = NULL;
            bool bExternFrom = false;
            bool bExternTo = false;

            // port arbitrator at the destination
            arbPort = Glib::RefPtr<PortArbitratorModel>::cast_dynamic(destination);

            // source 
            intPort = Glib::RefPtr<InternalPortModel>::cast_dynamic(source);
            if(intPort)
            {
                output = intPort->getOutput();
                module = (Module*) output->owner();
                strFrom = string(module->getPrefix()) + string(intPort->getOutput()->getPort()); 
                dummyLabel = string(intPort->getOutput()->getPort());
                if(!strCarrier.size())
                {
                    strCarrier = intPort->getOutput()->getCarrier();
                    if(arbPort)
                        strCarrier += "+recv.priority";
                }                    
            }
            else
            {
                extPort = Glib::RefPtr<ExternalPortModel>::cast_dynamic(source);
                strFrom = extPort->getPort();
                dummyLabel = string(extPort->getPort());
                if(!strCarrier.size() && arbPort)
                    strCarrier = "udp+recv.priority";
                bExternFrom = true;
            }
          
            // destination
            intPort = Glib::RefPtr<InternalPortModel>::cast_dynamic(destination);
            if(intPort)
            {
                input = intPort->getInput();
                module = (Module*) input->owner();
                strTo = string(module->getPrefix()) + string(intPort->getInput()->getPort()); 
                dummyLabel += string(" -> ") + string(intPort->getInput()->getPort()) + string(" "); 
                if(!strCarrier.size())   
                {
                    strCarrier = intPort->getInput()->getCarrier();
                    if(arbPort)
                        strCarrier += "+recv.priority";
                }                    
            }
            else if(arbPort)
            {
                intPort = Glib::RefPtr<InternalPortModel>::cast_dynamic(arbPort->getPortModel());
                extPort = Glib::RefPtr<ExternalPortModel>::cast_dynamic(arbPort->getPortModel());
                if(intPort)
                {
                    input = intPort->getInput();
                    module = (Module*) input->owner();
                    strTo = string(module->getPrefix()) + string(intPort->getInput()->getPort()); 
                    dummyLabel += string(" -> ") + string(intPort->getInput()->getPort()) + string(" "); 
                    if(!strCarrier.size())
                    {
                        strCarrier = intPort->getInput()->getCarrier();
                        strCarrier += "+recv.priority";
                    }                        
                }
                else
                {
                    strTo = extPort->getPort();
                    dummyLabel += string(" -> ") + string(extPort->getPort()) + string(" "); 
                    bExternTo = true;
                    if(!strCarrier.size())
                        strCarrier = "udp+recv.priority";
                }
            }
            else
            {
                extPort = Glib::RefPtr<ExternalPortModel>::cast_dynamic(destination);
                strTo = extPort->getPort();
                dummyLabel += string(" -> ") + string(extPort->getPort()) + string(" "); 
                bExternTo = true;
                if(!strCarrier.size())
                        strCarrier = "udp";
            }
            
            connection.setFrom(strFrom.c_str());
            connection.setTo(strTo.c_str());
            connection.setCarrier(strCarrier.c_str());
            connection.setFromExternal(bExternFrom);
            connection.setToExternal(bExternTo);
            connection.setCorOutputData(output);
            connection.setCorInputData(input);
            connection.setModel(this);
            connection = parentWindow->manager.getKnowledgeBase()->addConnectionToApplication(application, connection);
            tool = TooltipModel::create(parentWindow, dummyLabel.c_str());
        }

        strLabel = strCarrier;
        this->property_stroke_color().set_value(defaultColor.c_str());
        if(strLabel.size())
            label = LabelModel::create(parentWindow, this, strLabel.c_str());
        else
            label = LabelModel::create(parentWindow, this, strCarrier.c_str());

        // if it is an auxilary connections
        /*
        if((strLabel.find("virtual") != std::string::npos) || 
           (strLabel.find("auxiliary") != std::string::npos) )
        {
            GooCanvasLineDash *dash = goo_canvas_line_dash_new (ARROW_LINEWIDTH, 3.0, 3.0);
            g_object_set(this->gobj(), "line-dash", dash, NULL);      
        }
        */

        if(bNested)
        {
            applicationModel->add_child(label);
            label->property_visibility().set_value(Goocanvas::ITEM_HIDDEN);
        }
        else
            parentWindow->getRootModel()->add_child(label);
        label->raise();

        showLabel(parentWindow->m_showLabel);
    }

    
    Gdk::Point pt1 = source->getContactPoint(this);
    Gdk::Point pt2 = destination->getContactPoint(this);
    setPoint(0, pt1.get_x(), pt1.get_y()-ARROW_LINEWIDTH/2.0);
    Goocanvas::Points points = this->property_points().get_value();
    setPoint(points.get_num_points()-1, pt2.get_x(), pt2.get_y()-ARROW_LINEWIDTH/2.0);
    setLabel(strLabel.c_str());
    updatCoordiantes();
    //printf("%s : %d\n", __FILE__, __LINE__); 
}
示例#2
0
void ApplicationModel::updateChildItems(void)
{

    ModulePContainer modules = parentWindow->manager.getKnowledgeBase()->getModules(application);
    CnnContainer connections = parentWindow->manager.getKnowledgeBase()->getConnections(application);
    ApplicaitonPContainer applications = parentWindow->manager.getKnowledgeBase()->getApplications(application);

    int index = 0; //index = (index/900)*100+50;
    CnnIterator citr;
    for(citr=connections.begin(); citr<connections.end(); citr++)
    {
        Connection baseCon = *citr;
        GraphicModel model = baseCon.getModelBase();
        InputData* input = NULL;
        OutputData* output = NULL;
        Glib::RefPtr<PortModel> source(NULL);
        Glib::RefPtr<PortModel> dest(NULL);
        findInputOutputData((*citr), modules, input, output);
        if(output)
            source = findModelFromOutput(output);
        else
        {
            Glib::RefPtr<ExternalPortModel> extPort;
            bool bExist = false;
            for(int i=0; i<get_n_children(); i++)
            {
                extPort = Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i));
                if(extPort && compareString(extPort->getPort(), baseCon.from()))
                {
                    source = extPort;
                    bExist = true;
                    break;
                }
            }
            if(!bExist)
            {
                source = ExternalPortModel::create(parentWindow, OUTPUTD, (*citr).from(), true);
                add_child(source);
                 double x ,y;
                if(model.points.size() > 1)
                {
                    x = model.points[1].x - Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getWidth()
                                              - bounds.get_x1()+ITEMS_MARGIE;
                    y = model.points[1].y - Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getHeight()/2.0
                                              - bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE;
                    source->set_property("x", x);
                    source->set_property("y", y);
                }
                else
                {
                    x = 10;
                    y = index;
                    source->set_property("x", 10);
                    source->set_property("y", index);
                }

                double end_x, end_y;
                double start_x;
                Goocanvas::Points points = poly->property_points().get_value();
                points.get_coordinate(4, end_x, end_y);
                points.get_coordinate(5, start_x, end_y);
                double port_w = Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getWidth();
                double port_h = Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getHeight();
                if((x + port_w + ITEMS_MARGIE) >= end_x)
                    width = x + port_w + ITEMS_MARGIE;
                if((y + port_h + ITEMS_MARGIE) >= end_y)
                    height = y + port_h + ITEMS_MARGIE;

                double minx = start_x;
                if(x < start_x)
                {
                    minx = x - ITEMS_MARGIE;
                    text->translate(-abs(start_x-x)-ITEMS_MARGIE, 0);
                }
                points.set_coordinate(0, minx, 0);
                points.set_coordinate(1, text_w+TEXT_MARGINE*2+minx, 0);
                points.set_coordinate(2, text_w+TEXT_MARGINE*2+minx, text_h+TEXT_MARGINE);
                points.set_coordinate(3, width, text_h+TEXT_MARGINE);
                points.set_coordinate(4, width, height);
                points.set_coordinate(5, minx, height);
                poly->property_points().set_value(points);
                Goocanvas::Points points3(3);
                points3.set_coordinate(0, width, text_h+TEXT_MARGINE);
                points3.set_coordinate(1, width, height);
                points3.set_coordinate(2, minx, height);
                shadow->property_points().set_value(points3);
            }
            index+=40;
        }

        if(input)
           dest = findModelFromInput(input);
        else
        {
            Glib::RefPtr<ExternalPortModel> extPort;
            bool bExist = false;
            for(int i=0; i<get_n_children(); i++)
            {
                extPort = Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i));
                if(extPort && compareString(extPort->getPort(), baseCon.to()))
                {
                    dest = extPort;
                    bExist = true;
                    break;
                }
            }
            if(!bExist)
            {
                double x,y;
                dest = ExternalPortModel::create(parentWindow, INPUTD, (*citr).to(), true);
                add_child(dest);
                size_t size = model.points.size();
                if(size > 2)
                {
                    x = model.points[size-1].x-bounds.get_x1()+ITEMS_MARGIE;
                    y = model.points[size-1].y - Glib::RefPtr<ExternalPortModel>::cast_dynamic(dest)->getHeight()/2.0
                                            - bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE;
                    dest->set_property("x", x);
                    dest->set_property("y", y);
                }
                else
                {
                    x = 400;
                    y = index;
                    dest->set_property("x", x);
                    dest->set_property("y", y);
                }
                double end_x, end_y;
                Goocanvas::Points points = poly->property_points().get_value();
                points.get_coordinate(4, end_x, end_y);
                double port_w = Glib::RefPtr<ExternalPortModel>::cast_dynamic(dest)->getWidth();
                double port_h = Glib::RefPtr<ExternalPortModel>::cast_dynamic(dest)->getHeight();
                if((x + port_w + ITEMS_MARGIE) >= end_x)
                    width = x + port_w + ITEMS_MARGIE;
                if((y + port_h + ITEMS_MARGIE) >= end_y)
                    height = y + port_h + ITEMS_MARGIE;

                points.set_coordinate(3, width, text_h+TEXT_MARGINE);
                points.set_coordinate(4, width, height);
                points.get_coordinate(5, end_x, end_y);
                points.set_coordinate(5, end_x, height);
                poly->property_points().set_value(points);
                Goocanvas::Points points3(3);
                points3.set_coordinate(0, width, text_h+TEXT_MARGINE);
                points3.set_coordinate(1, width, height);
                points3.set_coordinate(2, end_x, height);
                shadow->property_points().set_value(points3);
            }
        }

        if(source && dest)
        {
            Glib::RefPtr<ArrowModel> arrow = ArrowModel::create(parentWindow, source, dest, &baseCon, this);
            add_child(arrow);
            int size = model.points.size();
            for(int i=2; i<size-1; i++)
                arrow->addMidPoint(model.points[i].x-bounds.get_x1()+ITEMS_MARGIE,
                                   model.points[i].y-bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE, i-2);
            arrow->setSelected(false);
            if(size)
                arrow->setLabelPosition(model.points[0].x-bounds.get_x1()+ITEMS_MARGIE,
                                        model.points[0].y-bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE);
        }
    }
}