コード例 #1
0
int ArrowModel::addPoint(double x, double y)
{
    int index = 0;
    double x1, y1;
    double x2, y2;

    Goocanvas::Points points = this->property_points().get_value();
    for(int i=0; i<points.get_num_points()-1; i++)
    {
        points.get_coordinate(i, x1, y1);
        points.get_coordinate(i+1, x2, y2);
        if((x > fmin(x1, x2)) && (x < fmax(x1, x2)) &&
           (y > fmin(y1, y2)) && (y < fmax(y1, y2)))
        {   
            double d = ((x-x1)*(x2-x1) + (y-y1)*(y2-y1)) / ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
            if((d > 0.0) && (d < 1.0))
            {
                index = i;
                break;
            }
        }
    }

    addPoint(index, x, y);
    return index+1;
}
コード例 #2
0
bool ArrowModel::intersect(double p1, double q1, double p2, double q2)
{
    double x1, y1;
    double x2, y2;
    Goocanvas::Points points = this->property_points().get_value();
    for(int i=0; i<points.get_num_points()-1; i++)
    {
        points.get_coordinate(i, x1, y1);
        points.get_coordinate(i+1, x2, y2);

        // calculte intersection 
        double s1_x, s1_y, s2_x, s2_y;
        s1_x = x2 - x1;     
        s1_y = y2 - y1;
        s2_x = p2 - p1;     
        s2_y = q2 - q1;

        double s, t;
        s = (-s1_y * (x1 - p1) + s1_x * (y1 - q1)) / (-s2_x * s1_y + s1_x * s2_y);
        t = ( s2_x * (y1 - q1) - s2_y * (x1 - p1)) / (-s2_x * s1_y + s1_x * s2_y);

        if ((s >= 0) && (s <= 1) && (t >= 0) && (t <= 1))
            return true;
    }

    return false;
}
コード例 #3
0
void ArrowModel::onPointUpdated(void)
{
    GraphicModel::points.clear();
    double x1, y1;
    GyPoint pt;

    if(!bNullArrow)
    {
        // Adding label position 
        Glib::RefPtr<Goocanvas::Item> item = parentWindow->m_Canvas->get_item(label); 
        if(item)
        {
            Goocanvas::Bounds bi = item->get_bounds();
            bi = item->get_bounds();
            pt.x = bi.get_x1();
            pt.y = bi.get_y1();
        }
        else
            pt.x = pt.y = -1;
    }

    GraphicModel::points.push_back(pt);

    Goocanvas::Points pts = this->property_points().get_value();
    for(int i=0; i<pts.get_num_points(); i++)
    {
        pts.get_coordinate(i, x1, y1);
        pt.x = x1;
        pt.y = y1;
        GraphicModel::points.push_back(pt);
    }
}
コード例 #4
0
bool ArrowModel::inside(double p1, double q1, double p2, double q2)
{
    double x1, y1;
    double x2, y2;
    Goocanvas::Points points = this->property_points().get_value();
    points.get_coordinate(0, x1, y1);
    points.get_coordinate(points.get_num_points()-1, x2, y2);
    x1 = fmin(x1, x2);
    x2 = fmax(x1, x2);
    y1 = fmin(y1, y2);
    y2 = fmax(y1, y2);

    if((x1>=p1) && (x1<=p2) && (y1>=q1) && (y2<=q2))
        return true;
 
    return false;
}
コード例 #5
0
Gdk::Point ArrowModel::getPoint(int index)
{
    Goocanvas::Points points = this->property_points().get_value();
    if(index >= points.get_num_points())
        return Gdk::Point(-1,-1);
    double x, y;
    points.get_coordinate(index, x, y);
    return Gdk::Point((int)x,(int)y);
}
コード例 #6
0
int ArrowModel::getIndex(double x, double y)
{
    double x1, y1;
    Goocanvas::Points points = this->property_points().get_value();
    for(int i=0; i<points.get_num_points(); i++)
    {
        points.get_coordinate(i, x1, y1);
        if((x1 == x) && (y1 == y))
            return i;
    }
    
    return -1;
}
コード例 #7
0
// add a new point after index
bool ArrowModel::addPoint(int index, double x, double y)
{
    Goocanvas::Points points = this->property_points().get_value();
    if(index >= points.get_num_points())
        return false;

    Goocanvas::Points new_points(points.get_num_points()+1);
    for(int i=0; i<=index; i++)
    {
        double _x, _y;
        points.get_coordinate(i, _x, _y);
        new_points.set_coordinate(i, _x, _y);
    }
    new_points.set_coordinate(index+1, x, y);
    for(int i=index+1; i<points.get_num_points(); i++)
    {
        double _x, _y;
        points.get_coordinate(i, _x, _y);
        new_points.set_coordinate(i+1, _x, _y);
    }
    this->property_points().set_value(new_points);
    onPointUpdated();
    return true;
}
コード例 #8
0
void ArrowModel::updatLabelCoordiante(void)
{
    
    if(!bNullArrow)
    {
        Goocanvas::Points points = this->property_points().get_value();
        if(points.get_num_points() < 3)
        {
            double x1, y1, x2, y2;
            Goocanvas::Points points = this->property_points().get_value();
            int index = points.get_num_points() / 2;
            points.get_coordinate(index-1, x1, y1);
            points.get_coordinate(index, x2, y2);
            
            int text_w, text_h;
            PangoLayout *layout = gtk_widget_create_pango_layout((GtkWidget*)parentWindow->gobj(), strLabel.c_str());
            PangoFontDescription *fontdesc = pango_font_description_from_string("Monospace 9");
            pango_layout_set_font_description (layout, fontdesc);
            pango_layout_get_pixel_size (layout, &text_w, &text_h);

            setLabelPosition((x1+x2)/2.0 - text_w/2.0, (y1+y2)/2.0);
        }            
    }       
}
コード例 #9
0
bool ArrowModel::setPoint(double x, double y,
                          double x_new, double y_new)
{
    double x1, y1;
    Goocanvas::Points points = this->property_points().get_value();
    for(int i=0; i<points.get_num_points(); i++)
    {
        points.get_coordinate(i, x1, y1);
        if((x1 == x) && (y1 == y))
        {
            points.set_coordinate(i, x_new, y_new);
            break;
        }
    }
    this->property_points().set_value(points);
    onPointUpdated();
    return true;
}
コード例 #10
0
ApplicationModel::ApplicationModel(ApplicationWindow* parentWnd, Application* app) : GroupModel()
{
    parentWindow = parentWnd;
    application = app;
    app->setModel(this);

    // adding application name
    text = Goocanvas::TextModel::create(app->getName());
#ifdef GLIBMM_PROPERTIES_ENABLED
    text->property_font() = FONT_DESC;
    text->property_alignment().set_value(Pango::ALIGN_CENTER);
#endif

    PangoLayout *layout = gtk_widget_create_pango_layout((GtkWidget*)parentWindow->gobj(),
                            app->getName());
    PangoFontDescription *fontdesc = pango_font_description_from_string(FONT_DESC);
    pango_layout_set_font_description (layout, fontdesc);
    pango_layout_get_pixel_size (layout, &text_w, &text_h);

    text->property_x().set_value(TEXT_MARGINE);
    text->property_y().set_value(text_h/2.0);

    poly = Goocanvas::PolylineModel::create(0,0,0,0);
    poly->property_close_path().set_value(true);
    poly->property_line_width().set_value(1.2);
    //poly->property_fill_color().set_value(APPLICATION_COLOR);
    poly->property_fill_color_rgba().set_value(APPLICATION_COLOR);
    poly->property_stroke_color().set_value("DodgerBlue3");
    //GooCanvasLineDash *dash = goo_canvas_line_dash_new (2, 3.0, 3.0);
    //g_object_set(poly->gobj(), "line-dash", dash, NULL);

    shadow = Goocanvas::PolylineModel::create(0,0,0,0);
    shadow->property_close_path().set_value(false);
    shadow->property_line_width().set_value(3.0);
    shadow->property_stroke_color().set_value("gray");

    getApplicationBounds(bounds);

    width = MAX(MIN_WIDTH + text_w, bounds.get_x2()-bounds.get_x1() + 2*ITEMS_MARGIE);
    height = MAX(MIN_HEIGHT, bounds.get_y2()-bounds.get_y1() + 2*ITEMS_MARGIE + text_h);
    Goocanvas::Points points(6);
    points.set_coordinate(0, 0, 0);
    points.set_coordinate(1, text_w+TEXT_MARGINE*2, 0);
    points.set_coordinate(2, text_w+TEXT_MARGINE*2, text_h+TEXT_MARGINE);
    points.set_coordinate(3, width, text_h+TEXT_MARGINE);
    points.set_coordinate(4, width, height);
    points.set_coordinate(5, 0, 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, 0, height);
    shadow->property_points().set_value(points3);
    shadow->translate(1,1);

    this->add_child(shadow);
    this->add_child(poly);
    this->add_child(text);


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

    int index = 0;
    ModulePIterator itr;
    for(itr=modules.begin(); itr!=modules.end(); itr++)
    {
        Module* module = (*itr);
        Glib::RefPtr<ModuleModel> mod = ModuleModel::create(parentWindow, module, true);
        this->add_child(mod);
        double x, y;
        x = (module->getModelBase().points.size()>0) ? module->getModelBase().points[0].x : index%900+10;
        y = (module->getModelBase().points.size()>0) ? module->getModelBase().points[0].y : ((index+=300)/900)*100+10;
        x -= bounds.get_x1();
        x += ITEMS_MARGIE;
        y -= bounds.get_y1();
        y += ITEMS_MARGIE + text_h + TEXT_MARGINE;
        mod->translate(x, y);

        double end_x, end_y;
        Goocanvas::Points points = poly->property_points().get_value();
        points.get_coordinate(4, end_x, end_y);
        if((x + mod->getWidth() + ITEMS_MARGIE) >= end_x)
            width = x + mod->getWidth() + ITEMS_MARGIE;
        if((y + mod->getHeight() + ITEMS_MARGIE) >= end_y)
            height = y + mod->getHeight() + ITEMS_MARGIE;

        //points.set_coordinate(0, 0, 0);
        //points.set_coordinate(1, text_w+TEXT_MARGINE*2, 0);
        //points.set_coordinate(2, text_w+TEXT_MARGINE*2, text_h+TEXT_MARGINE);
        points.set_coordinate(3, width, text_h+TEXT_MARGINE);
        points.set_coordinate(4, width, height);
        points.set_coordinate(5, 0, 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, 0, height);
        shadow->property_points().set_value(points3);
    }

}
コード例 #11
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);
        }
    }
}