vymmodel.cpp
changeset 673 234b4900dfa8
parent 660 d0e047b8d412
child 676 3dabc6424d73
     1.1 --- a/vymmodel.cpp	Wed Jan 16 15:45:20 2008 +0000
     1.2 +++ b/vymmodel.cpp	Wed Feb 27 16:09:06 2008 +0000
     1.3 @@ -16,9 +16,8 @@
     1.4  
     1.5  void VymModel::clear() 
     1.6  {
     1.7 -	for (int i=0; i<mapCenters.count(); i++)
     1.8 -		mapCenters.at(i)->clear();
     1.9 -	mapCenters.clear();	
    1.10 +	while (!mapCenters.isEmpty())
    1.11 +		delete mapCenters.takeFirst();
    1.12  }
    1.13  
    1.14  void VymModel::init () 
    1.15 @@ -116,6 +115,7 @@
    1.16  	BranchObj *bo=bo_start;
    1.17  	if (bo)
    1.18  	{
    1.19 +		// Try to find next branch in current MapCenter
    1.20  		rbo=bo->next();
    1.21  		if (rbo) return rbo;
    1.22  
    1.23 @@ -216,6 +216,70 @@
    1.24  		mapCenters.at(i)->reposition();	//	for positioning heading
    1.25  }
    1.26  
    1.27 +QPolygonF VymModel::shape(BranchObj *bo)
    1.28 +{
    1.29 +	// Creating (arbitrary) shapes
    1.30 +
    1.31 +	QPolygonF p;
    1.32 +	QRectF rb=bo->getBBox();
    1.33 +	if (bo->getDepth()==0)
    1.34 +	{
    1.35 +		// Just take BBox of this mapCenter
    1.36 +		p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
    1.37 +		return p;
    1.38 +	}
    1.39 +
    1.40 +	// Take union of BBox and TotalBBox 
    1.41 +
    1.42 +	QRectF ra=bo->getTotalBBox();
    1.43 +	if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
    1.44 +		p   <<ra.bottomLeft()
    1.45 +			<<ra.topLeft()
    1.46 +			<<QPointF (rb.topLeft().x(), ra.topLeft().y() )
    1.47 +			<<rb.topRight()
    1.48 +			<<rb.bottomRight()
    1.49 +			<<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
    1.50 +	else		
    1.51 +		p   <<ra.bottomRight()
    1.52 +			<<ra.topRight()
    1.53 +			<<QPointF (rb.topRight().x(), ra.topRight().y() )
    1.54 +			<<rb.topLeft()
    1.55 +			<<rb.bottomLeft()
    1.56 +			<<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
    1.57 +	return p;		
    1.58 +
    1.59 +}
    1.60 +
    1.61 +void VymModel::moveAway(LinkableMapObj *lmo)
    1.62 +{
    1.63 +	// Autolayout:
    1.64 +	//
    1.65 +	// Move all branches and MapCenters away from lmo 
    1.66 +	// to avoid collisions 
    1.67 +
    1.68 +	// 
    1.69 +
    1.70 +
    1.71 +	QPolygonF pA;
    1.72 +	QPolygonF pB;
    1.73 +
    1.74 +	BranchObj *boA=(BranchObj*)lmo;
    1.75 +	BranchObj *boB;
    1.76 +	for (int i=0; i<mapCenters.count(); i++)
    1.77 +	{
    1.78 +		boB=mapCenters.at(i);
    1.79 +		pA=shape (boA);
    1.80 +		pB=shape (boB);
    1.81 +		PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
    1.82 +		cout <<"------->"
    1.83 +			<<"="<<r.intersect
    1.84 +			<<"  ("<<qPrintable(boA->getHeading() )<<")"
    1.85 +			<<"  with ("<< qPrintable (boB->getHeading() )
    1.86 +			<<")  willIntersect"
    1.87 +			<<r.willIntersect 
    1.88 +			<<"  minT="<<r.minTranslation<<endl<<endl;
    1.89 +	}
    1.90 +}
    1.91  
    1.92  
    1.93  //////////////////////////////////////////////