more fixes for collisions
authorinsilmaril
Fri, 11 Sep 2009 12:56:15 +0000
changeset 794d922fb6ea482
parent 793 cac93797c580
child 795 6b0a5f4923d3
more fixes for collisions
branchobj.cpp
mapeditor.cpp
mapobj.cpp
mapobj.h
treeitem.cpp
treeitem.h
treemodel.cpp
vymmodel.cpp
vymmodel.h
     1.1 --- a/branchobj.cpp	Wed Sep 09 12:57:06 2009 +0000
     1.2 +++ b/branchobj.cpp	Fri Sep 11 12:56:15 2009 +0000
     1.3 @@ -3,7 +3,7 @@
     1.4  #include "branchitem.h"
     1.5  #include "geometry.h"
     1.6  #include "mapeditor.h"
     1.7 -#include "mainwindow.h"
     1.8 +#include "mainwindow.h"   
     1.9  #include "misc.h"
    1.10  
    1.11  extern FlagRow *standardFlagsMaster;
    1.12 @@ -16,9 +16,13 @@
    1.13  BranchObj::BranchObj (QGraphicsScene* s,TreeItem *ti):OrnamentedObj (s)
    1.14  {
    1.15  //    cout << "Const BranchObj (s)  \n";
    1.16 -	parObj=NULL;
    1.17      scene=s;
    1.18  	treeItem=ti;
    1.19 +	BranchItem *pi=(BranchItem*)(ti->parent());
    1.20 +	if (pi && pi!=ti->getModel()->getRootItem() )
    1.21 +		parObj=pi->getLMO();
    1.22 +	else
    1.23 +		parObj=NULL;
    1.24  	init();
    1.25  }
    1.26  
    1.27 @@ -715,14 +719,28 @@
    1.28  
    1.29  ConvexPolygon BranchObj::getBoundingPolygon()
    1.30  {
    1.31 -	if (treeItem->branchCount()==0)
    1.32 +/*
    1.33 +	if (!pi)	//FIXME-3 Testing only
    1.34 +	{
    1.35 +		pi=scene->addPolygon(MapObj::getBoundingPolygon() );
    1.36 +		pi->setPen(Qt::NoPen);
    1.37 +		pi->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
    1.38 +		pi->setZValue(Z_BBOX);
    1.39 +	}
    1.40 +	*/
    1.41 +	if (treeItem->branchCount()==0 || treeItem->depth()==0)
    1.42 +	{
    1.43 +		if (pi) pi->setPolygon (MapObj::getBoundingPolygon() );
    1.44  		return MapObj::getBoundingPolygon();
    1.45 +	}
    1.46  
    1.47 +	calcBBoxSizeWithChildren();	//FIXME-3 really needed?
    1.48  	QPolygonF p;
    1.49  	p<<bboxTotal.topLeft();
    1.50  	p<<bboxTotal.topRight();
    1.51  	p<<bboxTotal.bottomRight();
    1.52  	p<<bboxTotal.bottomLeft();
    1.53 +		if (pi) pi->setPolygon (p );
    1.54  	return p;
    1.55  }
    1.56  
     2.1 --- a/mapeditor.cpp	Wed Sep 09 12:57:06 2009 +0000
     2.2 +++ b/mapeditor.cpp	Fri Sep 11 12:56:15 2009 +0000
     2.3 @@ -560,7 +560,7 @@
     2.4  void MapEditor::testFunction2()
     2.5  {
     2.6  	// Create list with all bounding polygons
     2.7 -	QList <MapObj*> mapobjects;
     2.8 +	QList <LinkableMapObj*> mapobjects;
     2.9  	QList <ConvexPolygon> polys; 
    2.10  	ConvexPolygon p;
    2.11  	QList <Vector> vectors;
    2.12 @@ -570,25 +570,16 @@
    2.13  	BranchItem *bi;
    2.14  	BranchItem *bi2;
    2.15  	BranchObj *bo;
    2.16 -	BranchItem *ri=model->getRootItem();
    2.17 -	for (int i=0;i<ri->branchCount();++i)
    2.18 +
    2.19 +	// Outer loop: Iterate until we no more changes in orientation 
    2.20 +	bool orientationChanged=true;
    2.21 +	while (orientationChanged)
    2.22  	{
    2.23 -		bi=ri->getBranchNum (i);
    2.24 -		bo=(BranchObj*)bi->getLMO();
    2.25 -		if (bo)
    2.26 +		BranchItem *ri=model->getRootItem();
    2.27 +		for (int i=0;i<ri->branchCount();++i)
    2.28  		{
    2.29 -			mapobjects.append (bo);
    2.30 -			p=bo->getBoundingPolygon();
    2.31 -			p.calcCentroid();
    2.32 -			polys.append(p);
    2.33 -			vectors.append (QPointF(0,0));
    2.34 -			orgpos.append (p.at(0));
    2.35 -			headings.append (bi->getHeading());
    2.36 -		}
    2.37 -		for (int j=0;j<bi->branchCount();++j)
    2.38 -		{
    2.39 -			bi2=bi->getBranchNum (j);
    2.40 -			bo=(BranchObj*)bi2->getLMO();
    2.41 +			bi=ri->getBranchNum (i);
    2.42 +			bo=(BranchObj*)bi->getLMO();
    2.43  			if (bo)
    2.44  			{
    2.45  				mapobjects.append (bo);
    2.46 @@ -597,57 +588,85 @@
    2.47  				polys.append(p);
    2.48  				vectors.append (QPointF(0,0));
    2.49  				orgpos.append (p.at(0));
    2.50 -				headings.append (bi2->getHeading());
    2.51 -			}	
    2.52 -		}
    2.53 -	}
    2.54 -
    2.55 -	// Iterate moving bounding polygons until we have no more collisions
    2.56 -	int collisions=1;
    2.57 -	while (collisions>0)
    2.58 -	{
    2.59 -		collisions=0;
    2.60 -		for (int i=0; i<polys.size()-1; ++i)
    2.61 -		{
    2.62 -			for (int j=i+1; j<polys.size();++j)
    2.63 +				headings.append (bi->getHeading());
    2.64 +			}
    2.65 +			for (int j=0;j<bi->branchCount();++j)
    2.66  			{
    2.67 -				if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
    2.68 +				bi2=bi->getBranchNum (j);
    2.69 +				bo=(BranchObj*)bi2->getLMO();
    2.70 +				if (bo)
    2.71  				{
    2.72 -					collisions++;
    2.73 -					v=polys.at(j).centroid()-polys.at(i).centroid();
    2.74 -					// Move also away if centroids are identical
    2.75 -					if (v.isNull()) 
    2.76 -					{
    2.77 -						//cout << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v<<"  "<<headings[i].toStdString()<<" - "<<headings[j].toStdString()<<"  ";
    2.78 -						v.setX (rand()%200 -100);
    2.79 -						v.setY (rand()%200 -100);
    2.80 -						//cout << v;
    2.81 -					}
    2.82 -					v.normalize();
    2.83 -					v.scale (2);
    2.84 -					//cout <<  "  "<<v<<endl;
    2.85 -					vectors[j]=v;
    2.86 -					vectors[i]=v;
    2.87 -					vectors[i].invert();
    2.88 -				}  
    2.89 +					mapobjects.append (bo);
    2.90 +					p=bo->getBoundingPolygon();
    2.91 +					p.calcCentroid();
    2.92 +					polys.append(p);
    2.93 +					vectors.append (QPointF(0,0));
    2.94 +					orgpos.append (p.at(0));
    2.95 +					headings.append (bi2->getHeading());
    2.96 +				}	
    2.97  			}
    2.98  		}
    2.99 -		for (int i=0;i<vectors.size();i++)
   2.100 +
   2.101 +		// Iterate moving bounding polygons until we have no more collisions
   2.102 +		int collisions=1;
   2.103 +		while (collisions>0)
   2.104  		{
   2.105 -			//cout << " v="<<vectors[i]<<" "<<headings[i].toStdString()<<endl;
   2.106 -			polys[i].translate (vectors[i]);
   2.107 -		}
   2.108 -		//cout << "Collisions: "<<collisions<<endl;
   2.109 -		//collisions=0;
   2.110 -	}	
   2.111 +			collisions=0;
   2.112 +			for (int i=0; i<polys.size()-1; ++i)
   2.113 +			{
   2.114 +				for (int j=i+1; j<polys.size();++j)
   2.115 +				{
   2.116 +					if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
   2.117 +					{
   2.118 +						collisions++;
   2.119 +						//cout << "Collision: "<<headings[i].toStdString()<<" - "<<headings[j].toStdString()<<endl;
   2.120 +						v=polys.at(j).centroid()-polys.at(i).centroid();
   2.121 +						// Move also away if centroids are identical
   2.122 +						if (v.isNull()) 
   2.123 +						{
   2.124 +							//cout << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v<<endl;
   2.125 +							v.setX (rand()%200 -100);
   2.126 +							v.setY (rand()%200 -100);
   2.127 +							//cout << v;
   2.128 +						}
   2.129 +						v.normalize();
   2.130 +						v.scale (2);
   2.131 +						//cout <<  "  v="<<v<<endl;
   2.132 +						vectors[j]=v;
   2.133 +						vectors[i]=v;
   2.134 +						vectors[i].invert();
   2.135 +					}  
   2.136 +				}
   2.137 +			}
   2.138 +			for (int i=0;i<vectors.size();i++)
   2.139 +			{
   2.140 +				//cout << " v="<<vectors[i]<<" "<<headings[i].toStdString()<<endl;
   2.141 +				polys[i].translate (vectors[i]);
   2.142 +			}
   2.143 +			cout << "Collisions: "<<collisions<<endl;
   2.144 +			//collisions=0;
   2.145 +		}	
   2.146  
   2.147 -	// Finally move the real objects and update 
   2.148 -	for (int i=0;i<polys.size();i++)
   2.149 -	{
   2.150 -		Vector v=polys[i].at(0)-orgpos[i];
   2.151 -		mapobjects[i]->moveBy(v.x(),v.y() );
   2.152 -	}	
   2.153 -	model->reposition();	
   2.154 +		// Finally move the real objects and update 
   2.155 +		QList <LinkableMapObj::Orientation> orients;
   2.156 +		for (int i=0;i<polys.size();i++)
   2.157 +		{
   2.158 +			Vector v=polys[i].at(0)-orgpos[i];
   2.159 +			orients.append (mapobjects[i]->getOrientation());
   2.160 +			mapobjects[i]->moveBy(v.x(),v.y() );
   2.161 +		}	
   2.162 +		model->reposition();	
   2.163 +		orientationChanged=false;
   2.164 +		for (int i=0;i<polys.size();i++)
   2.165 +			if (orients[i]!=mapobjects[i]->getOrientation())
   2.166 +			{
   2.167 +				orientationChanged=true;
   2.168 +				break;
   2.169 +			}
   2.170 +		cout << "Final: orientChanged="<<orientationChanged<<endl;
   2.171 +		break;
   2.172 +		//orientationChanged=false;
   2.173 +	} // loop if orientation has changed
   2.174  }
   2.175  
   2.176  BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
   2.177 @@ -1190,6 +1209,7 @@
   2.178  					lmosel->setRelPos();	
   2.179  				} 
   2.180  
   2.181 +			} // depth>0
   2.182  				// Maybe we can relink temporary?
   2.183  				if (dsti)
   2.184  				{
   2.185 @@ -1208,7 +1228,6 @@
   2.186  				}		
   2.187  				// reposition subbranch
   2.188  				lmosel->reposition();	
   2.189 -			} // depth>0
   2.190  
   2.191  			QItemSelection sel=model->getSelectionModel()->selection();
   2.192  			updateSelection(sel,sel);	// position has changed
   2.193 @@ -1278,7 +1297,11 @@
   2.194  			tmpXLink->setEnd ( ((BranchItem*)dsti) );
   2.195  			tmpXLink->updateXLink();
   2.196  			tmpXLink->activate(); 
   2.197 -			//FIXME-0 model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );	
   2.198 +			model->saveState(
   2.199 +				tmpXLink,QString("delete ()"),
   2.200 +				dsti,QString("addXLink (\"%1\",\"%2\")").arg(model->getSelectString(tmpXLink->getBegin())).arg(model->getSelectString(dsti)),
   2.201 +				QString("Add xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(dsti)) 
   2.202 +			);	
   2.203  		} else
   2.204  		{
   2.205  			model->deleteItem(tmpXLink);
     3.1 --- a/mapobj.cpp	Wed Sep 09 12:57:06 2009 +0000
     3.2 +++ b/mapobj.cpp	Fri Sep 11 12:56:15 2009 +0000
     3.3 @@ -36,6 +36,7 @@
     3.4  {
     3.5      absPos=QPointF(0,0);
     3.6      visible=true;
     3.7 +	pi=NULL;
     3.8  }
     3.9  
    3.10  void MapObj::copy(MapObj* other)
     4.1 --- a/mapobj.h	Wed Sep 09 12:57:06 2009 +0000
     4.2 +++ b/mapobj.h	Fri Sep 11 12:56:15 2009 +0000
     4.3 @@ -63,6 +63,7 @@
     4.4  
     4.5  	TreeItem *treeItem;				//! Crossrefence to treemodel
     4.6  
     4.7 +	QGraphicsPolygonItem *pi;	//FIXME-3 testing only
     4.8  };
     4.9  
    4.10  #endif
     5.1 --- a/treeitem.cpp	Wed Sep 09 12:57:06 2009 +0000
     5.2 +++ b/treeitem.cpp	Fri Sep 11 12:56:15 2009 +0000
     5.3 @@ -278,9 +278,9 @@
     5.4  	{
     5.5  		case MapCenter: return childItems.indexOf (item) - branchOffset;
     5.6  		case Branch: return childItems.indexOf (item) - branchOffset;
     5.7 -		case Image: return parentItem->childItems.indexOf (item) - imageOffset;
     5.8 -		case Attribute: return parentItem->childItems.indexOf (item) - attributeOffset;
     5.9 -		case XLink: return parentItem->childItems.indexOf (item) - xlinkOffset;
    5.10 +		case Image: return childItems.indexOf (item) - imageOffset;
    5.11 +		case Attribute: return childItems.indexOf (item) - attributeOffset;
    5.12 +		case XLink: return childItems.indexOf (item) - xlinkOffset;
    5.13  		default: return -1;
    5.14  	}
    5.15  }
    5.16 @@ -601,6 +601,14 @@
    5.17  		return NULL;
    5.18  }
    5.19  
    5.20 +AttributeItem* TreeItem::getAttributeNum (const int &n)
    5.21 +{
    5.22 +	if (n>=0 && n<attributeCounter)
    5.23 +		return (AttributeItem*)getChildNum (attributeOffset + n);
    5.24 +	else
    5.25 +		return NULL;
    5.26 +}
    5.27 +
    5.28  XLinkItem* TreeItem::getXLinkNum (const int &n)	
    5.29  {
    5.30  	if (n>=0 && n<xlinkCounter )
     6.1 --- a/treeitem.h	Wed Sep 09 12:57:06 2009 +0000
     6.2 +++ b/treeitem.h	Fri Sep 11 12:56:15 2009 +0000
     6.3 @@ -9,11 +9,12 @@
     6.4  #include "noteobj.h"
     6.5  #include "xmlobj.h"
     6.6  
     6.7 -class LinkableMapObj;
     6.8 +class AttributeItem;
     6.9  class BranchObj;
    6.10  class BranchItem;
    6.11  class FloatImageObj;
    6.12  class ImageItem;
    6.13 +class LinkableMapObj;
    6.14  class VymModel;
    6.15  class XLinkItem;
    6.16  class XLinkObj;
    6.17 @@ -21,7 +22,7 @@
    6.18  class TreeItem:public XMLObj
    6.19  {
    6.20  public:
    6.21 -	enum Type {Undefined,MapCenter,Branch,Image,Attribute,XLink};	//FIXME-3 MapCenter still needed?
    6.22 +	enum Type {Undefined,MapCenter,Branch,Image,Attribute,XLink};
    6.23  	enum HideTmpMode {HideNone, HideExport};
    6.24  
    6.25      TreeItem();
    6.26 @@ -155,6 +156,8 @@
    6.27  	virtual ImageItem* getImageNum(const int &n);
    6.28  	virtual FloatImageObj* getImageObjNum(const int &n);
    6.29  
    6.30 +	virtual AttributeItem* getAttributeNum(const int &n);
    6.31 +
    6.32  	virtual XLinkItem* getXLinkNum(const int &n);
    6.33  	virtual XLinkObj* getXLinkObjNum(const int &n);
    6.34  
     7.1 --- a/treemodel.cpp	Wed Sep 09 12:57:06 2009 +0000
     7.2 +++ b/treemodel.cpp	Fri Sep 11 12:56:15 2009 +0000
     7.3 @@ -228,10 +228,14 @@
     7.4  bool TreeModel::removeRows ( int row, int count, const QModelIndex & parent)
     7.5  {
     7.6  	int last=row+count-1;
     7.7 -    TreeItem *pi= getItem (parent);
     7.8 +    TreeItem *pi;
     7.9 +	if (parent.isValid())
    7.10 +		pi=getItem (parent);
    7.11 +	else
    7.12 +		pi=rootItem;
    7.13  	TreeItem *ti;
    7.14  
    7.15 -	cout << "TM::removeRows  row="<<row<<"  count="<<count<<endl;
    7.16 +	cout << "TM::removeRows  pi="<<pi<<"  row="<<row<<"  count="<<count<<endl;
    7.17  	for (int i=row; i<=last; i++)
    7.18  	{
    7.19  		ti=pi->getChildNum (row);
     8.1 --- a/vymmodel.cpp	Wed Sep 09 12:57:06 2009 +0000
     8.2 +++ b/vymmodel.cpp	Fri Sep 11 12:56:15 2009 +0000
     8.3 @@ -1135,7 +1135,11 @@
     8.4  	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
     8.5  
     8.6  	// select  object before undo
     8.7 -	select (undoSelection);
     8.8 +	if (!select (undoSelection))
     8.9 +	{
    8.10 +		qWarning ("VymModel::undo()  Could not select object for undo");
    8.11 +		return;
    8.12 +	}
    8.13  
    8.14  	if (debug)
    8.15  	{
    8.16 @@ -1424,11 +1428,12 @@
    8.17  		parts.removeFirst();
    8.18  		if (typ=="mc" || typ=="bo")
    8.19  			ti=ti->getBranchNum (n);
    8.20 -			/* FIXME-2		add other types to getSelectionString and findBy...
    8.21 -		else
    8.22 -			if (typ="fi")
    8.23 -				ti=ti->getImageNum (n);
    8.24 -				*/
    8.25 +		else if (typ=="fi")
    8.26 +			ti=ti->getImageNum (n);
    8.27 +		else if (typ=="ai")
    8.28 +			ti=ti->getAttributeNum (n);
    8.29 +		else if (typ=="xl")
    8.30 +			ti=ti->getXLinkNum (n);
    8.31  		if(!ti) return NULL;		
    8.32  	}
    8.33  	return  ti;
    8.34 @@ -2347,7 +2352,12 @@
    8.35  			select (pi);
    8.36  			reposition();
    8.37  			emitShowSelection();
    8.38 -		}
    8.39 +		} else if (ti->getType()==TreeItem::XLink)
    8.40 +		{
    8.41 +			//FIXME-2 savestate missing
    8.42 +			deleteItem (ti);
    8.43 +		} else
    8.44 +			qWarning ("VymmModel::deleteSelection()  unknown type?!");
    8.45  	}
    8.46  }
    8.47  
    8.48 @@ -2427,7 +2437,7 @@
    8.49  
    8.50  TreeItem* VymModel::deleteItem (TreeItem *ti)
    8.51  {
    8.52 -	cout << "VM::deleteItem "<<ti<<endl;
    8.53 +	cout << "VM::deleteItem "<<ti<<"  "<<getSelectString(ti).toStdString()<<endl;
    8.54  	if (ti)
    8.55  	{
    8.56  		TreeItem *pi=ti->parent();
    8.57 @@ -2950,6 +2960,34 @@
    8.58  		} else
    8.59  			parser.setError (Aborted,"Wrong number of parameters");
    8.60  	/////////////////////////////////////////////////////////////////////
    8.61 +	} else if (com==QString("addXLink"))
    8.62 +	{
    8.63 +		if (parser.parCount()>1)
    8.64 +		{
    8.65 +			s=parser.parString (ok,0);	// begin
    8.66 +			t=parser.parString (ok,1);	// end
    8.67 +			BranchItem *begin=(BranchItem*)findBySelectString(s);
    8.68 +			BranchItem *end=(BranchItem*)findBySelectString(t);
    8.69 +			if (begin && end)
    8.70 +			{
    8.71 +				if (begin->isBranchLikeType() && end->isBranchLikeType())
    8.72 +				{
    8.73 +					XLinkItem *xl=createXLink (begin,true);
    8.74 +					if (xl)
    8.75 +					{
    8.76 +						xl->setEnd (end);
    8.77 +						xl->activate();
    8.78 +					} else
    8.79 +						parser.setError (Aborted,"Failed to create xLink");
    8.80 +				}
    8.81 +				else
    8.82 +					parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
    8.83 +				
    8.84 +			} else
    8.85 +				parser.setError (Aborted,"Couldn't select begin or end of xLink");
    8.86 +		} else
    8.87 +			parser.setError (Aborted,"Need at least 2 parameters for begin and end");
    8.88 +	/////////////////////////////////////////////////////////////////////
    8.89  	} else if (com=="clearFlags")	
    8.90  	{
    8.91  		if (!selti )
    8.92 @@ -4306,64 +4344,59 @@
    8.93  	return defXLinkWidth;
    8.94  }
    8.95  
    8.96 -void VymModel::move(const double &x, const double &y)	// FIXME-3
    8.97 +void VymModel::move(const double &x, const double &y)
    8.98  {
    8.99  	int i=x; i=y;
   8.100 -/*
   8.101 -	BranchObj *bo = getSelectedBranch();
   8.102 -	if (bo && 
   8.103 -		(selectionType()==TreeItem::Branch ||
   8.104 -		 selectionType()==TreeItem::MapCenter ||
   8.105 -		 selectionType()==TreeItem::Image
   8.106 -		))
   8.107 +	MapItem *seli = (MapItem*)getSelectedItem();
   8.108 +	if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
   8.109  	{
   8.110 -        QPointF ap(bo->getAbsPos());
   8.111 -        QPointF to(x, y);
   8.112 -        if (ap != to)
   8.113 -        {
   8.114 -            QString ps=qpointfToString(ap);
   8.115 -            QString s=getSelectString();
   8.116 -            saveState(
   8.117 -                s, "move "+ps, 
   8.118 -                s, "move "+qpointfToString(to), 
   8.119 -                QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
   8.120 -            bo->move(x,y);
   8.121 -            reposition();
   8.122 -            emitSelectionChanged();
   8.123 -        }
   8.124 +		LinkableMapObj *lmo=seli->getLMO();
   8.125 +		if (lmo)
   8.126 +		{
   8.127 +			QPointF ap(lmo->getAbsPos());
   8.128 +			QPointF to(x, y);
   8.129 +			if (ap != to)
   8.130 +			{
   8.131 +				QString ps=qpointFToString(ap);
   8.132 +				QString s=getSelectString(seli);
   8.133 +				saveState(
   8.134 +					s, "move "+ps, 
   8.135 +					s, "move "+qpointFToString(to), 
   8.136 +					QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
   8.137 +				lmo->move(x,y);
   8.138 +				reposition();
   8.139 +				emitSelectionChanged();
   8.140 +			}
   8.141 +		}
   8.142  	}
   8.143 -*/	
   8.144  }
   8.145  
   8.146 -void VymModel::moveRel (const double &x, const double &y)	// FIXME-3
   8.147 +void VymModel::moveRel (const double &x, const double &y)	
   8.148  {
   8.149  	int i=x; i=y;
   8.150 -/*
   8.151 -	BranchObj *bo = getSelectedBranch();
   8.152 -	if (bo && 
   8.153 -		(selectionType()==TreeItem::Branch ||
   8.154 -		 selectionType()==TreeItem::MapCenter ||
   8.155 -		 selectionType()==TreeItem::Image
   8.156 -		))
   8.157 -	if (bo)
   8.158 +	MapItem *seli = (MapItem*)getSelectedItem();
   8.159 +	if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
   8.160  	{
   8.161 -        QPointF rp(bo->getRelPos());
   8.162 -        QPointF to(x, y);
   8.163 -        if (rp != to)
   8.164 -        {
   8.165 -            QString ps=qpointfToString (bo->getRelPos());
   8.166 -            QString s=getSelectString(bo);
   8.167 -            saveState(
   8.168 -                s, "moveRel "+ps, 
   8.169 -                s, "moveRel "+qpointfToString(to), 
   8.170 -                QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
   8.171 -            ((OrnamentedObj*)bo)->move2RelPos (x,y);
   8.172 -            reposition();
   8.173 -            bo->updateLinkGeometry();
   8.174 -            emitSelectionChanged();
   8.175 -        }
   8.176 +		LinkableMapObj *lmo=seli->getLMO();
   8.177 +		if (lmo)
   8.178 +		{
   8.179 +			QPointF rp(lmo->getRelPos());
   8.180 +			QPointF to(x, y);
   8.181 +			if (rp != to)
   8.182 +			{
   8.183 +				QString ps=qpointFToString (lmo->getRelPos());
   8.184 +				QString s=getSelectString(seli);
   8.185 +				saveState(
   8.186 +					s, "moveRel "+ps, 
   8.187 +					s, "moveRel "+qpointFToString(to), 
   8.188 +					QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
   8.189 +				((OrnamentedObj*)lmo)->move2RelPos (x,y);
   8.190 +				reposition();
   8.191 +				lmo->updateLinkGeometry();
   8.192 +				emitSelectionChanged();
   8.193 +			}
   8.194 +		}	
   8.195  	}
   8.196 -*/	
   8.197  }
   8.198  
   8.199  
   8.200 @@ -4900,7 +4933,10 @@
   8.201  		case TreeItem::Branch: s="bo:";break;
   8.202  		case TreeItem::Image: s="fi:";break;
   8.203  		case TreeItem::Attribute: s="ai:";break;
   8.204 -		default:break;
   8.205 +		case TreeItem::XLink: s="xl:";break;
   8.206 +		default:
   8.207 +			s="unknown type in VymModel::getSelectString()";
   8.208 +			break;
   8.209  	}
   8.210  	s=  s + QString("%1").arg(ti->num());
   8.211  	if (ti->depth() >0)
     9.1 --- a/vymmodel.h	Wed Sep 09 12:57:06 2009 +0000
     9.2 +++ b/vymmodel.h	Fri Sep 11 12:56:15 2009 +0000
     9.3 @@ -190,6 +190,12 @@
     9.4  		const QString &comment, 
     9.5  		TreeItem *saveSelection);
     9.6  	/*! Overloaded for convenience */
     9.7 +    void saveStateComplete(
     9.8 +		TreeItem *undoSelection, 
     9.9 +		TreeItem* redoSelection, 
    9.10 +		const QString &redoCommand, 
    9.11 +		const QString &comment);
    9.12 +	/*! Overloaded for convenience */
    9.13      void saveStateChangingPart(
    9.14  		TreeItem *undoSelection, 
    9.15  		TreeItem* redoSelection,