# HG changeset patch
# User insilmaril
# Date 1268653782 0
# Node ID 31841b366d5e613da652e0ced7821073e2264b82
# Parent  0fad394bc330313a9bb75d515891458c9efb911c
Fixes for autoLayout (later)

diff -r 0fad394bc330 -r 31841b366d5e animpoint.cpp
--- a/animpoint.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/animpoint.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -104,7 +104,7 @@
 
 bool AnimPoint::animate()
 {
-	if (!animated) return animated;
+	if (!animated) return false;
 	n++;
 	if (n>animTicks)
 	{
@@ -112,7 +112,7 @@
 		animated=false;
 		setX (destPos.x() );
 		setY (destPos.y() );
-		return animated;
+		return false;
 	}
 
 	// Some math to slow down the movement in the end
diff -r 0fad394bc330 -r 31841b366d5e branchobj.cpp
--- a/branchobj.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/branchobj.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -738,15 +738,29 @@
 	anim=ap;
 }
 
+//#include <iostream>
 bool BranchObj::animate()
 {
 	anim.animate ();
 	if ( anim.isAnimated() )
 	{
-		setRelPos (anim);
+		//if (((MapItem*)treeItem)->getPositionMode()==MapItem::Relative) 
+		if (useRelPos)
+		{
+			setRelPos (anim);
+			//cout<<"Animating rel "<<treeItem->getHeading().toStdString()<<" "<<anim<<" "<<anim.getStart()<<"->"<<anim.getDest()<<"  "<<relPos<<endl;
+		}
+		else
+		{
+			move (anim);
+			//cout<<"Animating abs "<<treeItem->getHeading().toStdString()<<" "<<anim<<" "<<anim.getStart()<<"->"<<anim.getDest()<<"  "<<absPos<<endl;
+		}
 		return true;
 	}
-	parObj->reposition();	// we might have been relinked meanwhile
+	/*FIXME-3 reposition in BO:animate nearly never reached? needed?	
+	if (((MapItem*)treeItem)->getPositionMode()==MapItem::Relative)
+		parObj->reposition();	// we might have been relinked meanwhile
+	*/	
 	return false;
 }
 
diff -r 0fad394bc330 -r 31841b366d5e geometry.cpp
--- a/geometry.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/geometry.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -65,10 +65,18 @@
 {
 }
 
+//! Check if length is 0
+bool Vector::isNull()
+{
+	if (x()==0 && y()==0)
+		return true;
+	return false;	
+}
+
 //! Normalize vector
 void Vector::normalize ()
 {
-	if (x()==0 && y()==0) return;
+	if (isNull() ) return;
 	qreal l=sqrt ( x()*x() + y()*y() );
 	setX (x()/l);
 	setY (y()/l);
diff -r 0fad394bc330 -r 31841b366d5e geometry.h
--- a/geometry.h	Wed Mar 10 15:36:19 2010 +0000
+++ b/geometry.h	Mon Mar 15 11:49:42 2010 +0000
@@ -18,6 +18,7 @@
 	friend inline bool operator==(const Vector &v1, const Vector &v2 )
 	{ return v1.x()==v2.x() && v1.y()==v2.y(); }
 
+	bool isNull();
 	virtual void normalize ();
 	virtual qreal dotProduct (const QPointF &b);
 	virtual void scale  (const qreal &f);
diff -r 0fad394bc330 -r 31841b366d5e linkablemapobj.cpp
--- a/linkablemapobj.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/linkablemapobj.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -128,6 +128,11 @@
 	useRelPos=b;
 }
 
+bool LinkableMapObj::getUseRelPos ()
+{
+	return useRelPos;
+}
+
 void LinkableMapObj::setRelPos()
 {
 	if (parObj)
@@ -150,7 +155,11 @@
 
 QPointF LinkableMapObj::getRelPos()
 {
-	if (!parObj) return QPointF();
+	if (!parObj) 
+	{
+		qWarning("LMO::getRelPos parObj==0");
+		return QPointF();
+	}
 	return relPos;
 }
 
diff -r 0fad394bc330 -r 31841b366d5e linkablemapobj.h
--- a/linkablemapobj.h	Wed Mar 10 15:36:19 2010 +0000
+++ b/linkablemapobj.h	Mon Mar 15 11:49:42 2010 +0000
@@ -62,6 +62,7 @@
 	virtual bool hasParObjTmp();
 
 	virtual void setUseRelPos (const bool&);
+	virtual bool getUseRelPos();
 	virtual void setRelPos();				// set relPos to current parentPos
 	virtual void setRelPos(const QPointF&);	
 	virtual QPointF getRelPos();
diff -r 0fad394bc330 -r 31841b366d5e mainwindow.cpp
--- a/mainwindow.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/mainwindow.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -3130,7 +3130,7 @@
 void Main::editAddMapCenter()
 {
 	VymModel *m=currentModel();
-	if (m) m->addMapCenter ();
+	if (m) m->select (m->addMapCenter ());
 }
 
 void Main::editNewBranch()
diff -r 0fad394bc330 -r 31841b366d5e mapeditor.cpp
--- a/mapeditor.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/mapeditor.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -497,6 +497,7 @@
 */		
 }
 
+#include <iostream>
 void MapEditor::autoLayout()
 {
 	// Create list with all bounding polygons
@@ -559,7 +560,7 @@
 					if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
 					{
 						collisions++;
-						//qDebug() << "Collision: "<<headings[i]<<" - "<<headings[j];
+						if (debug) qDebug() << "Collision: "<<headings[i]<<" - "<<headings[j];
 						v=polys.at(j).centroid()-polys.at(i).centroid();
 						// Move also away if centroids are identical
 						if (v.isNull()) 
@@ -570,20 +571,22 @@
 							//qDebug() << v;
 						}
 						v.normalize();
-						v.scale (2);
 						//qDebug() <<  "  v="<<v;
-						vectors[j]=v;
-						vectors[i]=v;
+						vectors[j]=v*10000/polys.at(j).weight();		
+						vectors[i]=v*10000/polys.at(i).weight();		
 						vectors[i].invert();
+						//FIXME-3 outer loop, "i" get's changed several times...
+						// Better not move away from centroid of 2 colliding polys, but from centroid of _all_
 					}  
 				}
 			}
 			for (int i=0;i<vectors.size();i++)
 			{
 				//qDebug() << " v="<<vectors[i]<<" "<<headings[i];
+				if (!vectors[i].isNull() )
 				polys[i].translate (vectors[i]);
 			}
-			if (debug) qDebug()<< "Collisions: "<<collisions;
+			if (debug) qDebug()<< "Collisions total: "<<collisions;
 			//collisions=0;
 		}	
 
@@ -593,9 +596,14 @@
 		{
 			Vector v=polys[i].at(0)-orgpos[i];
 			orients.append (mapobjects[i]->getOrientation());
-		//	mapobjects[i]->moveBy(v.x(),v.y() );
-		//	mapobjects[i]->setRelPos();
-			model->startAnimation ((BranchObj*)mapobjects[i], mapobjects[i]->getAbsPos(), mapobjects[i]->getAbsPos() + v);
+			if (!v.isNull())
+			{
+				if (debug) cout<<" Moving "<<polys.at(i).weight()<<" "<<mapobjects[i]->getAbsPos()<<" -> "<<mapobjects[i]->getAbsPos() + v<<"  "<<headings[i].toStdString()<<endl;
+				//mapobjects[i]->moveBy(v.x(),v.y() );
+				//mapobjects[i]->setRelPos();
+				model->startAnimation ((BranchObj*)mapobjects[i], v);
+				if (debug) cout<<i<< " Weight: "<<polys.at(i).weight()<<" "<<v<<" "<<headings.at(i).toStdString()<<endl;
+			}
 		}	
 		/*
 		model->reposition();	
@@ -607,9 +615,9 @@
 				break;
 			}
 		*/
+	
 		break;
 
-
 		//orientationChanged=false;
 	} // loop if orientation has changed
 
diff -r 0fad394bc330 -r 31841b366d5e mapitem.cpp
--- a/mapitem.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/mapitem.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -61,6 +61,11 @@
 	posMode=mode;
 }
 
+MapItem::PositionMode MapItem::getPositionMode ()
+{
+	return posMode;
+}
+
 void MapItem::setHideLinkUnselected (bool b)
 {
 	hideLinkUnselected=b;
diff -r 0fad394bc330 -r 31841b366d5e mapitem.h
--- a/mapitem.h	Wed Mar 10 15:36:19 2010 +0000
+++ b/mapitem.h	Mon Mar 15 11:49:42 2010 +0000
@@ -41,6 +41,7 @@
 	/*! Tell object to use e.g. absolute positioning for mapcenter. 
 	    Defaulst is MapItem::Unused */
 	void setPositionMode (PositionMode mode);
+	PositionMode getPositionMode ();
 
 
 protected:
diff -r 0fad394bc330 -r 31841b366d5e tex/vym.changelog
--- a/tex/vym.changelog	Wed Mar 10 15:36:19 2010 +0000
+++ b/tex/vym.changelog	Mon Mar 15 11:49:42 2010 +0000
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Mon Mar 15 12:48:45 CET 2010 - vym@insilmaril.de
+
+- Bugfix: Several fixes for later autoLayout
+
 -------------------------------------------------------------------
 Wed Mar 10 16:35:23 CET 2010 - vym@insilmaril.de
 
diff -r 0fad394bc330 -r 31841b366d5e version.h
--- a/version.h	Wed Mar 10 15:36:19 2010 +0000
+++ b/version.h	Mon Mar 15 11:49:42 2010 +0000
@@ -7,7 +7,7 @@
 #define __VYM_VERSION "1.13.0"
 //#define __VYM_CODENAME "Codename: RC-1"
 #define __VYM_CODENAME "Codename: development version, not for production!"
-#define __VYM_BUILD_DATE "2010-03-10"
+#define __VYM_BUILD_DATE "2010-03-15"
 
 
 bool checkVersion(const QString &);
diff -r 0fad394bc330 -r 31841b366d5e vym.pro
--- a/vym.pro	Wed Mar 10 15:36:19 2010 +0000
+++ b/vym.pro	Mon Mar 15 11:49:42 2010 +0000
@@ -80,25 +80,25 @@
 	ornamentedobj.h \
 	parser.h \
 	process.h \
+	settings.h \
 	shortcuts.h\
 	showtextdialog.h\
 	simplescripteditor.h\
+	treeeditor.h \
+	treeitem.h \
+	treemodel.h \
 	texteditor.h \
-	treeeditor.h \
 	version.h \
 	vymmodel.h \
+	vymview.h \
+	warningdialog.h \
 	xlinkitem.h \
 	xlinkobj.h \
 	xml-base.h \
 	xml-vym.h \
 	xml-freemind.h \
 	xmlobj.h\
-	xsltproc.h \
-	settings.h \
-	treeitem.h \
-	treemodel.h \
-	vymview.h \
-	warningdialog.h
+	xsltproc.h 
 
 SOURCES	+= \
 	aboutdialog.cpp \
@@ -151,6 +151,7 @@
 	ornamentedobj.cpp \
 	parser.cpp \
 	process.cpp \
+	settings.cpp \
 	shortcuts.cpp\
 	showtextdialog.cpp \
 	simplescripteditor.cpp \
@@ -160,16 +161,15 @@
 	treemodel.cpp \
 	version.cpp \
 	vymmodel.cpp \
+	vymview.cpp \
+	warningdialog.cpp \
 	xlinkitem.cpp \
 	xlinkobj.cpp \
 	xml-base.cpp \
 	xml-vym.cpp \
 	xml-freemind.cpp \
 	xmlobj.cpp \
-	xsltproc.cpp \
-	settings.cpp \
-	vymview.cpp \
-	warningdialog.cpp
+	xsltproc.cpp 
 
 FORMS = \
 	attributewidget.ui \
diff -r 0fad394bc330 -r 31841b366d5e vymmodel.cpp
--- a/vymmodel.cpp	Wed Mar 10 15:36:19 2010 +0000
+++ b/vymmodel.cpp	Mon Mar 15 11:49:42 2010 +0000
@@ -2284,6 +2284,7 @@
 		QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
 		QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
 	);	
+	mapEditor->autoLayout();	//FIXME-3 testing
 	return bi;	
 }
 
@@ -4750,10 +4751,20 @@
 }
 
 
+void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
+{
+	if (!bo) return;
+
+	if (bo->getUseRelPos())
+		startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
+	else
+		startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
+}
+
 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
 {
 	if (start==dest) return;
-	if (bo && bo->getTreeItem()->depth()>0) 
+	if (bo && bo->getTreeItem()->depth()>=0) 
 	{
 		AnimPoint ap;
 		ap.setStart (start);
diff -r 0fad394bc330 -r 31841b366d5e vymmodel.h
--- a/vymmodel.h	Wed Mar 10 15:36:19 2010 +0000
+++ b/vymmodel.h	Mon Mar 15 11:49:42 2010 +0000
@@ -531,6 +531,7 @@
 private slots:
 	void animate();						//!< Called by timer to animate stuff
 public:
+	void startAnimation(BranchObj *bo, const QPointF &v);
 	void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
 	void stopAnimation(MapObj *mo);