Fixes for autoLayout (later)
authorinsilmaril
Mon Mar 15 11:49:42 2010 +0000 (2010-03-15)
changeset 83531841b366d5e
parent 834 0fad394bc330
child 836 62d621e3e550
Fixes for autoLayout (later)
animpoint.cpp
branchobj.cpp
geometry.cpp
geometry.h
linkablemapobj.cpp
linkablemapobj.h
mainwindow.cpp
mapeditor.cpp
mapitem.cpp
mapitem.h
tex/vym.changelog
version.h
vym.pro
vymmodel.cpp
vymmodel.h
     1.1 --- a/animpoint.cpp	Wed Mar 10 15:36:19 2010 +0000
     1.2 +++ b/animpoint.cpp	Mon Mar 15 11:49:42 2010 +0000
     1.3 @@ -104,7 +104,7 @@
     1.4  
     1.5  bool AnimPoint::animate()
     1.6  {
     1.7 -	if (!animated) return animated;
     1.8 +	if (!animated) return false;
     1.9  	n++;
    1.10  	if (n>animTicks)
    1.11  	{
    1.12 @@ -112,7 +112,7 @@
    1.13  		animated=false;
    1.14  		setX (destPos.x() );
    1.15  		setY (destPos.y() );
    1.16 -		return animated;
    1.17 +		return false;
    1.18  	}
    1.19  
    1.20  	// Some math to slow down the movement in the end
     2.1 --- a/branchobj.cpp	Wed Mar 10 15:36:19 2010 +0000
     2.2 +++ b/branchobj.cpp	Mon Mar 15 11:49:42 2010 +0000
     2.3 @@ -738,15 +738,29 @@
     2.4  	anim=ap;
     2.5  }
     2.6  
     2.7 +//#include <iostream>
     2.8  bool BranchObj::animate()
     2.9  {
    2.10  	anim.animate ();
    2.11  	if ( anim.isAnimated() )
    2.12  	{
    2.13 -		setRelPos (anim);
    2.14 +		//if (((MapItem*)treeItem)->getPositionMode()==MapItem::Relative) 
    2.15 +		if (useRelPos)
    2.16 +		{
    2.17 +			setRelPos (anim);
    2.18 +			//cout<<"Animating rel "<<treeItem->getHeading().toStdString()<<" "<<anim<<" "<<anim.getStart()<<"->"<<anim.getDest()<<"  "<<relPos<<endl;
    2.19 +		}
    2.20 +		else
    2.21 +		{
    2.22 +			move (anim);
    2.23 +			//cout<<"Animating abs "<<treeItem->getHeading().toStdString()<<" "<<anim<<" "<<anim.getStart()<<"->"<<anim.getDest()<<"  "<<absPos<<endl;
    2.24 +		}
    2.25  		return true;
    2.26  	}
    2.27 -	parObj->reposition();	// we might have been relinked meanwhile
    2.28 +	/*FIXME-3 reposition in BO:animate nearly never reached? needed?	
    2.29 +	if (((MapItem*)treeItem)->getPositionMode()==MapItem::Relative)
    2.30 +		parObj->reposition();	// we might have been relinked meanwhile
    2.31 +	*/	
    2.32  	return false;
    2.33  }
    2.34  
     3.1 --- a/geometry.cpp	Wed Mar 10 15:36:19 2010 +0000
     3.2 +++ b/geometry.cpp	Mon Mar 15 11:49:42 2010 +0000
     3.3 @@ -65,10 +65,18 @@
     3.4  {
     3.5  }
     3.6  
     3.7 +//! Check if length is 0
     3.8 +bool Vector::isNull()
     3.9 +{
    3.10 +	if (x()==0 && y()==0)
    3.11 +		return true;
    3.12 +	return false;	
    3.13 +}
    3.14 +
    3.15  //! Normalize vector
    3.16  void Vector::normalize ()
    3.17  {
    3.18 -	if (x()==0 && y()==0) return;
    3.19 +	if (isNull() ) return;
    3.20  	qreal l=sqrt ( x()*x() + y()*y() );
    3.21  	setX (x()/l);
    3.22  	setY (y()/l);
     4.1 --- a/geometry.h	Wed Mar 10 15:36:19 2010 +0000
     4.2 +++ b/geometry.h	Mon Mar 15 11:49:42 2010 +0000
     4.3 @@ -18,6 +18,7 @@
     4.4  	friend inline bool operator==(const Vector &v1, const Vector &v2 )
     4.5  	{ return v1.x()==v2.x() && v1.y()==v2.y(); }
     4.6  
     4.7 +	bool isNull();
     4.8  	virtual void normalize ();
     4.9  	virtual qreal dotProduct (const QPointF &b);
    4.10  	virtual void scale  (const qreal &f);
     5.1 --- a/linkablemapobj.cpp	Wed Mar 10 15:36:19 2010 +0000
     5.2 +++ b/linkablemapobj.cpp	Mon Mar 15 11:49:42 2010 +0000
     5.3 @@ -128,6 +128,11 @@
     5.4  	useRelPos=b;
     5.5  }
     5.6  
     5.7 +bool LinkableMapObj::getUseRelPos ()
     5.8 +{
     5.9 +	return useRelPos;
    5.10 +}
    5.11 +
    5.12  void LinkableMapObj::setRelPos()
    5.13  {
    5.14  	if (parObj)
    5.15 @@ -150,7 +155,11 @@
    5.16  
    5.17  QPointF LinkableMapObj::getRelPos()
    5.18  {
    5.19 -	if (!parObj) return QPointF();
    5.20 +	if (!parObj) 
    5.21 +	{
    5.22 +		qWarning("LMO::getRelPos parObj==0");
    5.23 +		return QPointF();
    5.24 +	}
    5.25  	return relPos;
    5.26  }
    5.27  
     6.1 --- a/linkablemapobj.h	Wed Mar 10 15:36:19 2010 +0000
     6.2 +++ b/linkablemapobj.h	Mon Mar 15 11:49:42 2010 +0000
     6.3 @@ -62,6 +62,7 @@
     6.4  	virtual bool hasParObjTmp();
     6.5  
     6.6  	virtual void setUseRelPos (const bool&);
     6.7 +	virtual bool getUseRelPos();
     6.8  	virtual void setRelPos();				// set relPos to current parentPos
     6.9  	virtual void setRelPos(const QPointF&);	
    6.10  	virtual QPointF getRelPos();
     7.1 --- a/mainwindow.cpp	Wed Mar 10 15:36:19 2010 +0000
     7.2 +++ b/mainwindow.cpp	Mon Mar 15 11:49:42 2010 +0000
     7.3 @@ -3130,7 +3130,7 @@
     7.4  void Main::editAddMapCenter()
     7.5  {
     7.6  	VymModel *m=currentModel();
     7.7 -	if (m) m->addMapCenter ();
     7.8 +	if (m) m->select (m->addMapCenter ());
     7.9  }
    7.10  
    7.11  void Main::editNewBranch()
     8.1 --- a/mapeditor.cpp	Wed Mar 10 15:36:19 2010 +0000
     8.2 +++ b/mapeditor.cpp	Mon Mar 15 11:49:42 2010 +0000
     8.3 @@ -497,6 +497,7 @@
     8.4  */		
     8.5  }
     8.6  
     8.7 +#include <iostream>
     8.8  void MapEditor::autoLayout()
     8.9  {
    8.10  	// Create list with all bounding polygons
    8.11 @@ -559,7 +560,7 @@
    8.12  					if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
    8.13  					{
    8.14  						collisions++;
    8.15 -						//qDebug() << "Collision: "<<headings[i]<<" - "<<headings[j];
    8.16 +						if (debug) qDebug() << "Collision: "<<headings[i]<<" - "<<headings[j];
    8.17  						v=polys.at(j).centroid()-polys.at(i).centroid();
    8.18  						// Move also away if centroids are identical
    8.19  						if (v.isNull()) 
    8.20 @@ -570,20 +571,22 @@
    8.21  							//qDebug() << v;
    8.22  						}
    8.23  						v.normalize();
    8.24 -						v.scale (2);
    8.25  						//qDebug() <<  "  v="<<v;
    8.26 -						vectors[j]=v;
    8.27 -						vectors[i]=v;
    8.28 +						vectors[j]=v*10000/polys.at(j).weight();		
    8.29 +						vectors[i]=v*10000/polys.at(i).weight();		
    8.30  						vectors[i].invert();
    8.31 +						//FIXME-3 outer loop, "i" get's changed several times...
    8.32 +						// Better not move away from centroid of 2 colliding polys, but from centroid of _all_
    8.33  					}  
    8.34  				}
    8.35  			}
    8.36  			for (int i=0;i<vectors.size();i++)
    8.37  			{
    8.38  				//qDebug() << " v="<<vectors[i]<<" "<<headings[i];
    8.39 +				if (!vectors[i].isNull() )
    8.40  				polys[i].translate (vectors[i]);
    8.41  			}
    8.42 -			if (debug) qDebug()<< "Collisions: "<<collisions;
    8.43 +			if (debug) qDebug()<< "Collisions total: "<<collisions;
    8.44  			//collisions=0;
    8.45  		}	
    8.46  
    8.47 @@ -593,9 +596,14 @@
    8.48  		{
    8.49  			Vector v=polys[i].at(0)-orgpos[i];
    8.50  			orients.append (mapobjects[i]->getOrientation());
    8.51 -		//	mapobjects[i]->moveBy(v.x(),v.y() );
    8.52 -		//	mapobjects[i]->setRelPos();
    8.53 -			model->startAnimation ((BranchObj*)mapobjects[i], mapobjects[i]->getAbsPos(), mapobjects[i]->getAbsPos() + v);
    8.54 +			if (!v.isNull())
    8.55 +			{
    8.56 +				if (debug) cout<<" Moving "<<polys.at(i).weight()<<" "<<mapobjects[i]->getAbsPos()<<" -> "<<mapobjects[i]->getAbsPos() + v<<"  "<<headings[i].toStdString()<<endl;
    8.57 +				//mapobjects[i]->moveBy(v.x(),v.y() );
    8.58 +				//mapobjects[i]->setRelPos();
    8.59 +				model->startAnimation ((BranchObj*)mapobjects[i], v);
    8.60 +				if (debug) cout<<i<< " Weight: "<<polys.at(i).weight()<<" "<<v<<" "<<headings.at(i).toStdString()<<endl;
    8.61 +			}
    8.62  		}	
    8.63  		/*
    8.64  		model->reposition();	
    8.65 @@ -607,9 +615,9 @@
    8.66  				break;
    8.67  			}
    8.68  		*/
    8.69 +	
    8.70  		break;
    8.71  
    8.72 -
    8.73  		//orientationChanged=false;
    8.74  	} // loop if orientation has changed
    8.75  
     9.1 --- a/mapitem.cpp	Wed Mar 10 15:36:19 2010 +0000
     9.2 +++ b/mapitem.cpp	Mon Mar 15 11:49:42 2010 +0000
     9.3 @@ -61,6 +61,11 @@
     9.4  	posMode=mode;
     9.5  }
     9.6  
     9.7 +MapItem::PositionMode MapItem::getPositionMode ()
     9.8 +{
     9.9 +	return posMode;
    9.10 +}
    9.11 +
    9.12  void MapItem::setHideLinkUnselected (bool b)
    9.13  {
    9.14  	hideLinkUnselected=b;
    10.1 --- a/mapitem.h	Wed Mar 10 15:36:19 2010 +0000
    10.2 +++ b/mapitem.h	Mon Mar 15 11:49:42 2010 +0000
    10.3 @@ -41,6 +41,7 @@
    10.4  	/*! Tell object to use e.g. absolute positioning for mapcenter. 
    10.5  	    Defaulst is MapItem::Unused */
    10.6  	void setPositionMode (PositionMode mode);
    10.7 +	PositionMode getPositionMode ();
    10.8  
    10.9  
   10.10  protected:
    11.1 --- a/tex/vym.changelog	Wed Mar 10 15:36:19 2010 +0000
    11.2 +++ b/tex/vym.changelog	Mon Mar 15 11:49:42 2010 +0000
    11.3 @@ -1,3 +1,8 @@
    11.4 +-------------------------------------------------------------------
    11.5 +Mon Mar 15 12:48:45 CET 2010 - vym@insilmaril.de
    11.6 +
    11.7 +- Bugfix: Several fixes for later autoLayout
    11.8 +
    11.9  -------------------------------------------------------------------
   11.10  Wed Mar 10 16:35:23 CET 2010 - vym@insilmaril.de
   11.11  
    12.1 --- a/version.h	Wed Mar 10 15:36:19 2010 +0000
    12.2 +++ b/version.h	Mon Mar 15 11:49:42 2010 +0000
    12.3 @@ -7,7 +7,7 @@
    12.4  #define __VYM_VERSION "1.13.0"
    12.5  //#define __VYM_CODENAME "Codename: RC-1"
    12.6  #define __VYM_CODENAME "Codename: development version, not for production!"
    12.7 -#define __VYM_BUILD_DATE "2010-03-10"
    12.8 +#define __VYM_BUILD_DATE "2010-03-15"
    12.9  
   12.10  
   12.11  bool checkVersion(const QString &);
    13.1 --- a/vym.pro	Wed Mar 10 15:36:19 2010 +0000
    13.2 +++ b/vym.pro	Mon Mar 15 11:49:42 2010 +0000
    13.3 @@ -80,25 +80,25 @@
    13.4  	ornamentedobj.h \
    13.5  	parser.h \
    13.6  	process.h \
    13.7 +	settings.h \
    13.8  	shortcuts.h\
    13.9  	showtextdialog.h\
   13.10  	simplescripteditor.h\
   13.11 +	treeeditor.h \
   13.12 +	treeitem.h \
   13.13 +	treemodel.h \
   13.14  	texteditor.h \
   13.15 -	treeeditor.h \
   13.16  	version.h \
   13.17  	vymmodel.h \
   13.18 +	vymview.h \
   13.19 +	warningdialog.h \
   13.20  	xlinkitem.h \
   13.21  	xlinkobj.h \
   13.22  	xml-base.h \
   13.23  	xml-vym.h \
   13.24  	xml-freemind.h \
   13.25  	xmlobj.h\
   13.26 -	xsltproc.h \
   13.27 -	settings.h \
   13.28 -	treeitem.h \
   13.29 -	treemodel.h \
   13.30 -	vymview.h \
   13.31 -	warningdialog.h
   13.32 +	xsltproc.h 
   13.33  
   13.34  SOURCES	+= \
   13.35  	aboutdialog.cpp \
   13.36 @@ -151,6 +151,7 @@
   13.37  	ornamentedobj.cpp \
   13.38  	parser.cpp \
   13.39  	process.cpp \
   13.40 +	settings.cpp \
   13.41  	shortcuts.cpp\
   13.42  	showtextdialog.cpp \
   13.43  	simplescripteditor.cpp \
   13.44 @@ -160,16 +161,15 @@
   13.45  	treemodel.cpp \
   13.46  	version.cpp \
   13.47  	vymmodel.cpp \
   13.48 +	vymview.cpp \
   13.49 +	warningdialog.cpp \
   13.50  	xlinkitem.cpp \
   13.51  	xlinkobj.cpp \
   13.52  	xml-base.cpp \
   13.53  	xml-vym.cpp \
   13.54  	xml-freemind.cpp \
   13.55  	xmlobj.cpp \
   13.56 -	xsltproc.cpp \
   13.57 -	settings.cpp \
   13.58 -	vymview.cpp \
   13.59 -	warningdialog.cpp
   13.60 +	xsltproc.cpp 
   13.61  
   13.62  FORMS = \
   13.63  	attributewidget.ui \
    14.1 --- a/vymmodel.cpp	Wed Mar 10 15:36:19 2010 +0000
    14.2 +++ b/vymmodel.cpp	Mon Mar 15 11:49:42 2010 +0000
    14.3 @@ -2284,6 +2284,7 @@
    14.4  		QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
    14.5  		QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
    14.6  	);	
    14.7 +	mapEditor->autoLayout();	//FIXME-3 testing
    14.8  	return bi;	
    14.9  }
   14.10  
   14.11 @@ -4750,10 +4751,20 @@
   14.12  }
   14.13  
   14.14  
   14.15 +void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
   14.16 +{
   14.17 +	if (!bo) return;
   14.18 +
   14.19 +	if (bo->getUseRelPos())
   14.20 +		startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
   14.21 +	else
   14.22 +		startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
   14.23 +}
   14.24 +
   14.25  void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
   14.26  {
   14.27  	if (start==dest) return;
   14.28 -	if (bo && bo->getTreeItem()->depth()>0) 
   14.29 +	if (bo && bo->getTreeItem()->depth()>=0) 
   14.30  	{
   14.31  		AnimPoint ap;
   14.32  		ap.setStart (start);
    15.1 --- a/vymmodel.h	Wed Mar 10 15:36:19 2010 +0000
    15.2 +++ b/vymmodel.h	Mon Mar 15 11:49:42 2010 +0000
    15.3 @@ -531,6 +531,7 @@
    15.4  private slots:
    15.5  	void animate();						//!< Called by timer to animate stuff
    15.6  public:
    15.7 +	void startAnimation(BranchObj *bo, const QPointF &v);
    15.8  	void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
    15.9  	void stopAnimation(MapObj *mo);
   15.10