autolayouteradapter.cpp
00001
00002
00003
00004
00005
00006
00007
00008
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
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
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
00166
00167
00168
00169 widget->setX(getCanvas()->getBaseX() +n->getX()-widget->getWidth()/2);
00170
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 }
This file is part of the documentation for umbrello Version 3.1.0.