umbrello API Documentation

autolayouteradapter.cpp

00001 /***************************************************************************
00002  *  copyright (C) 2005                                                     *
00003  *  Umbrello UML Modeller Authors <uml-devel @uml.sf.net>                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include "autolayouteradapter.h"
00013 
00014 
00015 namespace Autolayout
00016   {
00017 
00018   AutolayouterAdapter::AutolayouterAdapter()
00019       : Autolayout::Autolayouter()
00020     {}
00021 
00022 
00023   AutolayouterAdapter::~AutolayouterAdapter()
00024   {}}
00025 
00026 void Autolayout::AutolayouterAdapter::addRelationship( AssociationWidget * a )
00027   {
00028   int weight;
00029   switch (a->getAssocType())
00030     {
00031       case Uml::at_Generalization:;
00032       case Uml::at_Realization:
00033         {
00034         if (genralizationAsEdges)weight=generalizationWeight;
00035         else return;
00036         break;
00037         }
00038       case Uml::at_Dependency:
00039         {
00040         if (dependenciesAsEdges) weight=dependenciesWeight;
00041         else return;
00042         break;
00043         }
00044       case Uml::at_Anchor:
00045         {
00046         if (anchorsAsEdges) weight=anchorsWeight;
00047         else return;
00048         break;
00049         }
00050       case Uml::at_Aggregation:;
00051       case Uml::at_Association:;
00052       case Uml::at_Containment:;
00053       case Uml::at_Composition:;
00054       default: return;
00055       /*case Uml::at_Association_Self:;
00056       case Uml::at_Activity:;
00057       case Uml::at_Relationship:;
00058       case Uml::at_Coll_Message:;
00059       case Uml::at_Seq_Message:;
00060       case Uml::at_Coll_Message_Self:;
00061       case Uml::at_Seq_Message_Self:;
00062       case Uml::at_Containment:;
00063       case Uml::at_Composition:;
00064       case Uml::at_Realization:;
00065       case Uml::at_UniAssociation:;
00066 
00067       case Uml::at_State:;
00068       case Uml::at_Unknown:;
00069       */
00070     };
00071   getGraph()->addEdge(a->getWidgetID(Uml::A).c_str(),a->getWidgetID(Uml::B).c_str(),weight);
00072   }
00073 
00074 void Autolayout::AutolayouterAdapter::setAssociationWeight( int i )
00075   {
00076   associationWeight=i;
00077   }
00078 
00079 void Autolayout::AutolayouterAdapter::setDependenciesWeight( int i )
00080   {
00081   dependenciesWeight=i;
00082   }
00083 
00084 void Autolayout::AutolayouterAdapter::setGeneralizationWeight( int i )
00085   {
00086   generalizationWeight=i;
00087   }
00088 
00089 void Autolayout::AutolayouterAdapter::setGeneralizationAsEdges( bool b )
00090   {
00091   genralizationAsEdges=b;
00092   }
00093 
00094 void Autolayout::AutolayouterAdapter::setDependenciesAsEdges( bool b )
00095   {
00096   dependenciesAsEdges=b;
00097   }
00098 
00099 void Autolayout::AutolayouterAdapter::setAssociationAsEdges( bool b )
00100   {
00101   associationAsEdges=b;
00102   }
00103 
00104 void Autolayout::AutolayouterAdapter::setCompressShapes( bool b )
00105   {
00106   compressShapes=b;
00107   }
00108 
00109 void Autolayout::AutolayouterAdapter::setCenterDiagram( bool b )
00110   {
00111   centerDiagram=b;
00112   }
00113 
00114 void Autolayout::AutolayouterAdapter::setClusterizeHierarchies( bool b )
00115   {
00116   clusterizeHierarchies=b;
00117   }
00118 
00119 void Autolayout::AutolayouterAdapter::setShapeSeparation( int i )
00120   {
00121   shapeSeparation=i;
00122   }
00123 
00124 Autolayout::Graph  * Autolayout::AutolayouterAdapter::setGraph( UMLView * view )
00125   {
00126   if (! view) return 0;
00127   Autolayout::Graph * g=getGraph();
00128   if (g&&g->empty())
00129     {
00130     UMLWidgetList list = view->getWidgetList();
00131     UMLWidget* widget;
00132     for ( widget = list.first(); widget; widget= list.next() )
00133       {
00134       if (widget->getBaseType() == Uml::wt_Class)
00135         {
00136 
00137 
00138         g->addNode(widget->getID().c_str(),widget->getWidth(),
00139                    widget->getHeight());
00140         }
00141       }
00142     AssociationWidgetList as_list=view->getAssociationList();
00143     AssociationWidget* assoc;
00144     AssociationWidgetListIt it(as_list);
00145     while ( (assoc = it.current()) != 0 )
00146       {
00147       ++it;
00148       addRelationship(assoc);
00149       }
00150     }
00151   return g;
00152   }
00153 
00154 void Autolayout::AutolayouterAdapter::updateView( UMLView* view )
00155   {
00156 if (! view) return ;
00157 UMLWidgetList list = view->getWidgetList();
00158   UMLWidget* widget;
00159   Graph *g=getGraph();
00160   if (! view||!g)  return ;
00161   for ( widget = list.first(); widget; widget= list.next() )
00162     if (widget->getBaseType() == Uml::wt_Class)
00163       {
00164       Node* n =g->getNode(widget->getID().c_str());
00165       //printf("old values widgets %s x,y:%d,%d\n",widget->getID().c_str(),widget->getX(),widget->getY());
00166       //int x_old=widget->getX();
00167       //int x_calc=n.getX();
00168       //int x_calc2=30 +n.getX()-widget->getWidth()/2;
00169       widget->setX(getCanvas()->getBaseX() +n->getX()-widget->getWidth()/2);
00170       //int x=widget->getX();
00171       widget->setY(getCanvas()->getMaxY()/2-(n->getY()+(widget->getHeight()/2)));
00172 
00173       widget->updateWidget();
00174 
00175       }
00176   }
00177 
00178 Autolayout::Canvas * Autolayout::AutolayouterAdapter::setCanvas( UMLView* view )
00179   {
00180   return canvas=new Autolayout::SimpleCanvas(view->getCanvasWidth(),view->getCanvasHeight());
00181   }
00182 
00183 void Autolayout::AutolayouterAdapter::setNoteConnectionWeight( int i )
00184 {
00185 noteConnectionWeight=i;
00186 }
00187 
00188 void Autolayout::AutolayouterAdapter::setNoteConnectionsAsEdges( bool b )
00189 {
00190 noteConnectionAsEdges=b;
00191 }
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:54 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003