Ejemplo n.º 1
0
void ApplicationModel::updateBounds(void)
{
    for(int i=0; i<this->get_n_children(); i++)
    {
        Glib::RefPtr<Goocanvas::Item> item = parentWindow->m_Canvas->get_item(this->get_child(i));
        if(item)
        {
            Goocanvas::Bounds bd = item->get_bounds();
            bounds.set_x1( (bounds.get_x1() < bd.get_x1()) ? bounds.get_x1(): bd.get_x1() );
            bounds.set_x2( (bounds.get_x2() > bd.get_x2()) ? bounds.get_x2(): bd.get_x2() );
            bounds.set_y1( (bounds.get_y1() < bd.get_y1()) ? bounds.get_y1(): bd.get_y1() );
            bounds.set_y2( (bounds.get_y2() > bd.get_y2()) ? bounds.get_y2(): bd.get_y2() );
        }
    }

    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);

}
Ejemplo n.º 2
0
//TODO: check nested applications too
void ApplicationModel::getApplicationBounds(Goocanvas::Bounds& bounds)
{
    ModulePContainer modules = parentWindow->manager.getKnowledgeBase()->getModules(application);
    CnnContainer connections = parentWindow->manager.getKnowledgeBase()->getConnections(application);
    ApplicaitonPContainer applications = parentWindow->manager.getKnowledgeBase()->getApplications(application);

    ModulePIterator itr;
    bounds.set_x1(0);
    bounds.set_x2(0);
    bounds.set_y1(0);
    bounds.set_y2(0);
    for(itr=modules.begin(); itr!=modules.end(); itr++)
    {
        Module* module = (*itr);
        //if(module->owner() == application)
        //{
            if(module->getModelBase().points.size()>0)
            {
                if((bounds.get_x1() == 0) || (module->getModelBase().points[0].x < bounds.get_x1()) )
                    bounds.set_x1(module->getModelBase().points[0].x);
                if((bounds.get_x2() == 0) || (module->getModelBase().points[0].x > bounds.get_x1()) )
                    bounds.set_x2(module->getModelBase().points[0].x);
                if((bounds.get_y1() == 0) || (module->getModelBase().points[0].y < bounds.get_y1()) )
                    bounds.set_y1(module->getModelBase().points[0].y);
                if((bounds.get_y2() == 0) || (module->getModelBase().points[0].y > bounds.get_y2()) )
                    bounds.set_y2(module->getModelBase().points[0].y);
            }
        //}
     }

    CnnIterator citr;
    for(citr=connections.begin(); citr<connections.end(); citr++)
    {
        Connection baseCon = *citr;
        //if(baseCon.owner() == application)
        //{
            GraphicModel model = baseCon.getModelBase();
            int size = model.points.size();
            for(int i=0; i<size; i++)
            {
                if((bounds.get_x1() == -1) || (model.points[i].x < bounds.get_x1()) )
                    bounds.set_x1(model.points[i].x);
                if((bounds.get_x2() == -1) || (model.points[i].x > bounds.get_x2()) )
                    bounds.set_x2(model.points[i].x);
                if((bounds.get_y1() == -1) || (model.points[i].y < bounds.get_y1()) )
                    bounds.set_y1(model.points[i].y);
                if((bounds.get_y2() == -1) || (model.points[i].y > bounds.get_y2()) )
                    bounds.set_y2(model.points[i].y);
            }
        //}
    }
}
Ejemplo n.º 3
0
bool ApplicationModel::onItemMotionNotifyEvent(const Glib::RefPtr<Goocanvas::Item>& item,
                    GdkEventMotion* event)
{
    if(item && _dragging && (item == _dragging))
    {
        parentWindow->setModified();

        double new_x = event->x ;
        double new_y = event->y ;
        item->get_parent()->translate(new_x - _drag_x, new_y - _drag_y);

        Goocanvas::Bounds bi = item->get_parent()->get_bounds();
        bi = item->get_parent()->get_bounds();

        if(bi.get_x1() < 0)
            item->get_parent()->translate(-bi.get_x1(), 0);
        if(bi.get_y1() < 0)
            item->get_parent()->translate(0, -bi.get_y1());

        snapToGrid();

        bi = item->get_parent()->get_bounds();
        this->points.clear();
        GyPoint pt;
        pt.x = bi.get_x1();
        pt.y = bi.get_y1();
        this->points.push_back(pt);

        for(int i=0; i<get_n_children(); i++)
        {
            if(Glib::RefPtr<ModuleModel>::cast_dynamic(get_child(i)))
                Glib::RefPtr<ModuleModel>::cast_dynamic(get_child(i))->updateArrowCoordination();
            if(Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i)))
                Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i))->updateArrowCoordination();
        }

        // updating canvas boundries
        bool needUpdate = false;
        if(parentWindow->m_Canvas)
        {
            Goocanvas::Bounds bc;
            parentWindow->m_Canvas->get_bounds(bc);
            needUpdate = (bi.get_x2() > bc.get_x2()) || (bi.get_y2() > bc.get_y2());
            if(needUpdate)
            {
                new_x = (bi.get_x2() > bc.get_x2()) ? bi.get_x2() : bc.get_x2();
                new_y = (bi.get_y2() > bc.get_y2()) ? bi.get_y2() : bc.get_y2();
                parentWindow->m_Canvas->set_bounds(0,0, new_x, new_y);
                if(parentWindow->m_Grid)
                {
                    g_object_set(parentWindow->m_Grid, "width", new_x, NULL);
                    g_object_set(parentWindow->m_Grid, "height", new_y, NULL);
                }
            }
        }

    }
    return true;
}
Ejemplo n.º 4
0
bool ExternalPortModel::onItemMotionNotifyEvent(const Glib::RefPtr<Goocanvas::Item>& item, 
                    GdkEventMotion* event)
{
    if(bNested)
        return true;

    if(item && _dragging && item == _dragging)
    {
        parentWindow->setModified();
        double new_x = event->x ;
        double new_y = event->y ;   
        item->get_parent()->translate(new_x - _drag_x, new_y - _drag_y);
        
        Goocanvas::Bounds bi = item->get_bounds();
        bi = item->get_parent()->get_bounds();

        if(bi.get_x1() < 0)
            item->get_parent()->translate(-bi.get_x1(), 0);
        if(bi.get_y1() < 0)
            item->get_parent()->translate(0, -bi.get_y1());
       
        snapToGrid();

        // updating arrows coordination        
        updateArrowCoordination();

        bool needUpdate = false;
        if(parentWindow->m_Canvas)
        {
            Goocanvas::Bounds bc;
            parentWindow->m_Canvas->get_bounds(bc);
            needUpdate = (bi.get_x2() > bc.get_x2()) || (bi.get_y2() > bc.get_y2());
            if(needUpdate)
            {
                new_x = (bi.get_x2() > bc.get_x2()) ? bi.get_x2() : bc.get_x2(); 
                new_y = (bi.get_y2() > bc.get_y2()) ? bi.get_y2() : bc.get_y2(); 
                parentWindow->m_Canvas->set_bounds(0,0, new_x, new_y);            
                if(parentWindow->m_Grid)
                {
                    g_object_set(parentWindow->m_Grid, "width", new_x, NULL);
                    g_object_set(parentWindow->m_Grid, "height", new_y, NULL);
                }
            }
        }


    }
    return true;
}