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 return addMapCenter (QPointF(0,0));
87 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
89 MapCenterObj *mapCenter = new MapCenterObj(mapScene);
90 mapCenter->move (absPos);
91 mapCenter->setVisibility (true);
92 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
93 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
94 mapCenters.append(mapCenter);
98 MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco)
100 int i=mapCenters.indexOf (mco);
103 mapCenters.removeAt (i);
105 if (i>0) return mapCenters.at(i-1); // Return previous MCO
110 BranchObj* VymModel::first()
112 if (mapCenters.count()>0)
113 return mapCenters.first();
118 BranchObj* VymModel::next(BranchObj *bo_start)
121 BranchObj *bo=bo_start;
124 // Try to find next branch in current MapCenter
128 // Try to find MapCenter of bo
129 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
131 // Try to find next MapCenter
132 int i=mapCenters.indexOf ((MapCenterObj*)bo);
133 if (i+2 > mapCenters.count() || i<0) return NULL;
134 if (mapCenters.at(i+1)!=bo_start)
135 return mapCenters.at(i+1);
140 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
144 for (int i=0;i<mapCenters.count(); i++)
146 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
152 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
160 part=s.section(",",0,0);
162 num=part.right(part.length() - 3);
163 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
164 return mapCenters.at(num.toInt() );
167 for (int i=0; i<mapCenters.count(); i++)
169 lmo=mapCenters.at(i)->findObjBySelect(s);
175 LinkableMapObj* VymModel::findID (const QString &s)
178 for (int i=0; i<mapCenters.count(); i++)
180 lmo=mapCenters.at(i)->findID (s);
186 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
190 for (int i=0; i<mapCenters.count(); i++)
191 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
196 //////////////////////////////////////////////
198 //////////////////////////////////////////////
200 void VymModel::updateRelPositions()
202 for (int i=0; i<mapCenters.count(); i++)
203 mapCenters.at(i)->updateRelPositions();
206 void VymModel::reposition()
208 for (int i=0;i<mapCenters.count(); i++)
209 mapCenters.at(i)->reposition(); // for positioning heading
212 QPolygonF VymModel::shape(BranchObj *bo)
214 // Creating (arbitrary) shapes
217 QRectF rb=bo->getBBox();
218 if (bo->getDepth()==0)
220 // Just take BBox of this mapCenter
221 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
225 // Take union of BBox and TotalBBox
227 QRectF ra=bo->getTotalBBox();
228 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
231 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
234 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
238 <<QPointF (rb.topRight().x(), ra.topRight().y() )
241 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
246 void VymModel::moveAway(LinkableMapObj *lmo)
250 // Move all branches and MapCenters away from lmo
251 // to avoid collisions
259 BranchObj *boA=(BranchObj*)lmo;
261 for (int i=0; i<mapCenters.count(); i++)
263 boB=mapCenters.at(i);
266 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
269 <<" ("<<qPrintable(boA->getHeading() )<<")"
270 <<" with ("<< qPrintable (boB->getHeading() )
273 <<" minT="<<r.minTranslation<<endl<<endl;
278 //////////////////////////////////////////////
280 //////////////////////////////////////////////
283 // Only as long as we dont have Model/View yet
284 LinkableMapObj* VymModel::getSelection()
286 return mapEditor->getSelection();
288 BranchObj* VymModel::getSelectedBranch()
290 return mapEditor->getSelectedBranch();
294 bool VymModel::select (const QString &s)
296 return mapEditor->select (s);
299 QString VymModel::getSelectString (LinkableMapObj *lmo)
303 if (typeid(*lmo)==typeid(BranchObj) ||
304 typeid(*lmo)==typeid(MapCenterObj) )
306 LinkableMapObj *par=lmo->getParObj();
309 if (lmo->getDepth() ==1)
310 // Mainbranch, return
311 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
313 // Branch, call myself recursively
314 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
318 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
319 if (i>=0) s=QString("mc:%1").arg(i);
327 void VymModel::setHideTmp (HideTmpMode mode)
329 for (int i=0;i<mapCenters.count(); i++)
330 mapCenters.at(i)->setHideTmp (mode);
333 QRectF VymModel::getTotalBBox()
336 for (int i=0;i<mapCenters.count(); i++)
337 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);