1 #include <QApplication>
3 #include "geometry.h" // for addBBox
8 // cout << "Const VymModel\n";
14 // cout << "Destr VymModel\n";
17 void VymModel::clear()
19 while (!mapCenters.isEmpty())
20 delete mapCenters.takeFirst();
23 void VymModel::init ()
28 void VymModel::setMapEditor(MapEditor *me)
31 for (int i=0; i<mapCenters.count(); i++)
32 mapCenters.at(i)->setMapEditor(mapEditor);
35 MapEditor* VymModel::getMapEditor()
40 void VymModel::setVersion (const QString &s)
45 void VymModel::setAuthor (const QString &s)
50 QString VymModel::getAuthor()
55 void VymModel::setComment (const QString &s)
60 QString VymModel::getComment ()
65 QString VymModel::getDate ()
67 return QDate::currentDate().toString ("yyyy-MM-dd");
70 void VymModel::setScene (QGraphicsScene *s)
73 init(); // Here we have a mapScene set,
74 // which is (still) needed to create MapCenters
77 QGraphicsScene* VymModel::getScene ()
82 MapCenterObj* VymModel::addMapCenter()
84 MapCenterObj *mapCenter = new MapCenterObj(mapScene);
85 mapCenter->setVisibility (true);
86 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
87 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
88 mapCenters.append(mapCenter);
92 MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco)
94 int i=mapCenters.indexOf (mco);
97 mapCenters.removeAt (i);
99 if (i>0) return mapCenters.at(i-1); // Return previous MCO
104 BranchObj* VymModel::first()
106 if (mapCenters.count()>0)
107 return mapCenters.first();
112 BranchObj* VymModel::next(BranchObj *bo_start)
115 BranchObj *bo=bo_start;
118 // Try to find next branch in current MapCenter
122 // Try to find MapCenter of bo
123 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
126 // Try to find next MapCenter
127 int i=mapCenters.indexOf ((MapCenterObj*)bo);
128 if (i+1 > mapCenters.count() || i<0) return NULL;
129 if (mapCenters.at(i)!=bo_start)
130 return mapCenters.at(i);
135 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
139 for (int i=0;i<mapCenters.count(); i++)
141 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
147 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
155 part=s.section(",",0,0);
157 num=part.right(part.length() - 3);
158 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
159 return mapCenters.at(num.toInt() );
162 for (int i=0; i<mapCenters.count(); i++)
164 lmo=mapCenters.at(i)->findObjBySelect(s);
170 LinkableMapObj* VymModel::findID (const QString &s)
173 for (int i=0; i<mapCenters.count(); i++)
175 lmo=mapCenters.at(i)->findID (s);
181 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
185 for (int i=0; i<mapCenters.count(); i++)
186 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
191 //////////////////////////////////////////////
193 //////////////////////////////////////////////
195 /* FIXME copied from MCO, still needed?
196 void VymModel::updateLink()
198 // set childPos to middle of MapCenterObj
199 childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
200 childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
202 for (int i=0; i<branch.size(); ++i)
203 branch.at(i)->updateLink();
207 void VymModel::updateRelPositions()
209 for (int i=0; i<mapCenters.count(); i++)
210 mapCenters.at(i)->updateRelPositions();
213 void VymModel::reposition()
215 for (int i=0;i<mapCenters.count(); i++)
216 mapCenters.at(i)->reposition(); // for positioning heading
219 QPolygonF VymModel::shape(BranchObj *bo)
221 // Creating (arbitrary) shapes
224 QRectF rb=bo->getBBox();
225 if (bo->getDepth()==0)
227 // Just take BBox of this mapCenter
228 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
232 // Take union of BBox and TotalBBox
234 QRectF ra=bo->getTotalBBox();
235 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
238 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
241 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
245 <<QPointF (rb.topRight().x(), ra.topRight().y() )
248 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
253 void VymModel::moveAway(LinkableMapObj *lmo)
257 // Move all branches and MapCenters away from lmo
258 // to avoid collisions
266 BranchObj *boA=(BranchObj*)lmo;
268 for (int i=0; i<mapCenters.count(); i++)
270 boB=mapCenters.at(i);
273 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
276 <<" ("<<qPrintable(boA->getHeading() )<<")"
277 <<" with ("<< qPrintable (boB->getHeading() )
280 <<" minT="<<r.minTranslation<<endl<<endl;
285 //////////////////////////////////////////////
287 //////////////////////////////////////////////
290 // Only as long as we dont have Model/View yet
291 LinkableMapObj* VymModel::getSelection()
293 return mapEditor->getSelection();
295 BranchObj* VymModel::getSelectedBranch()
297 return mapEditor->getSelectedBranch();
301 bool VymModel::select (const QString &s)
303 return mapEditor->select (s);
306 QString VymModel::getSelectString (LinkableMapObj *lmo)
310 if (typeid(*lmo)==typeid(BranchObj) ||
311 typeid(*lmo)==typeid(MapCenterObj) )
313 LinkableMapObj *par=lmo->getParObj();
316 if (lmo->getDepth() ==1)
317 // Mainbranch, return
318 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
320 // Branch, call myself recursively
321 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
325 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
326 if (i>=0) s=QString("mc:%1").arg(i);
334 void VymModel::setHideTmp (HideTmpMode mode)
336 for (int i=0;i<mapCenters.count(); i++)
337 mapCenters.at(i)->setHideTmp (mode);
340 QRectF VymModel::getTotalBBox()
343 for (int i=0;i<mapCenters.count(); i++)
344 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);