El 06/09/2008 03:56 PM, Pau Arumí Albó escribió:
El dg 08 de 06 de 2008 a les 11:20 +0200, en/na David García Garzón va
escriure:
I would like to have a commit on the cut&paste patch, to accept this one separately. (i want the c&p working :-))) ) Pau, i'll do the commit of the patch before the positions in 30 min if you don't do it first.

I like the commited code. And like even more the pace of the
progress :-)

Thanks :)

Natanael, are there patches pending for revision?

Just the store and load of positions and sizes. I attached here an updated version. The major issue that I see with this code is the duplicated code for sizes and positions. In a while I'll send another version which makes all in one step.


Regards,
Natanael.

P



_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel


Index: NetworkEditor/src/NetworkCanvas.hxx
===================================================================
--- NetworkEditor/src/NetworkCanvas.hxx	(revision 11459)
+++ NetworkEditor/src/NetworkCanvas.hxx	(working copy)
@@ -1246,6 +1246,47 @@
 			box->resize(size);
 		}
 	}
+
+	bool updatePositionsOnXML()
+	{
+		CLAM::Network::ProcAttributesMap positionsMap;
+		CLAM::Network::ProcAttributesMap sizesMap;
+		for (unsigned i=0; i<_processings.size(); i++)
+		{
+			QPoint posProcessing = _processings[i]->pos();
+			QSize sizeProcessing = _processings[i]->size();
+			const std::string name=_processings[i]->getName().toStdString();
+			const std::string pos=(tr("%1,%2").arg(posProcessing.x()).arg(posProcessing.y())).toStdString();
+			const std::string size=(tr("%1,%2").arg(sizeProcessing.width()).arg(sizeProcessing.height())).toStdString();
+			positionsMap.insert(CLAM::Network::ProcAttributesMap::value_type(name,pos));
+			sizesMap.insert(CLAM::Network::ProcAttributesMap::value_type(name,size));
+		}
+		return (_network->UpdateProcBoxesPos(positionsMap) || _network->UpdateProcBoxesSizes(sizesMap));
+	}
+
+	void loadPositionsFromXML(QPoint offsetPoint = QPoint(0,0))
+	{
+		const CLAM::Network::ProcAttributesMap & ProcPosMap=_network->getProcBoxesPos();
+		CLAM::Network::ProcAttributesMap::const_iterator it;
+		for(it=ProcPosMap.begin();it!=ProcPosMap.end();it++)
+		{
+			QString name=QString(it->first.c_str());
+			QStringList stringsPos=QString(it->second.c_str()).split(",");
+			QPoint pos=offsetPoint+QPoint(stringsPos[0].toInt(),stringsPos[1].toInt());
+			ProcessingBox * box=getBox(name);
+			box->move(pos);
+		}
+
+		const CLAM::Network::ProcAttributesMap & ProcSizesMap=_network->getProcBoxesSizes();
+		for(it=ProcSizesMap.begin();it!=ProcSizesMap.end();it++)
+		{
+			QString name=QString(it->first.c_str());
+			QStringList stringsSize=QString(it->second.c_str()).split(",");
+			QSize size=QSize(stringsSize[0].toInt(),stringsSize[1].toInt());
+			ProcessingBox * box=getBox(name);
+			box->resize(size);
+		}
+	}
 private slots:
 	void onCopyConnection()
 	{
@@ -1291,6 +1332,7 @@
 		}
 		if (_network->UpdateSelections(processingsNamesList))
 			return;
+		updatePositionsOnXML();
 		CLAM::XmlStorage::Dump(*_network,"network",streamXMLBuffer);
 
 		QApplication::clipboard()->setText(QString(streamXMLBuffer.str().c_str()));
@@ -1331,6 +1373,7 @@
 			return;
 		}
 		reloadNetwork();
+		loadPositionsFromXML(point);
 	}
 
 
Index: CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.cxx
===================================================================
--- CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.cxx	(revision 11459)
+++ CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.cxx	(working copy)
@@ -30,8 +30,8 @@
 
 namespace CLAM
 {
-	ProcessingDefinitionAdapter::ProcessingDefinitionAdapter( Processing * adaptee, const std::string & name )
-		:  mAdaptee(adaptee), mName(name)
+	ProcessingDefinitionAdapter::ProcessingDefinitionAdapter( Processing * adaptee, const std::string & name, const std::string & pos, const std::string & size )
+		:  mAdaptee(adaptee), mName(name), mPos(pos), mSize(size)
 	{
 	}
 
@@ -47,7 +47,18 @@
 		XMLAdapter<Text> classNameAdapter( className, "type");
 		store.Store(nameAdapter);
 		store.Store(classNameAdapter);
-
+		if (mPos!="")
+		{
+			Text posCopy(mPos);
+			XMLAdapter<Text> posAdapter (posCopy, "boxPos");
+			store.Store(posAdapter);
+		}
+		if (mSize!="")
+		{
+			Text sizeCopy(mSize);
+			XMLAdapter<Text> sizeAdapter (sizeCopy, "boxSize");
+			store.Store(sizeAdapter);
+		}
 		XMLComponentAdapter configAdapter((ProcessingConfig&)mAdaptee->GetConfig());
 		store.Store(configAdapter);
 	}
@@ -60,6 +71,11 @@
 		XMLAdapter<Text> classNameAdapter( className, "type");
 		store.Load(classNameAdapter);
 
+		XMLAdapter<Text> posAdapter (mPos, "boxPos");
+		store.Load(posAdapter);
+		XMLAdapter<Text> sizeAdapter (mSize, "boxSize");
+		store.Load(sizeAdapter);
+
 		try
 		{
 			mAdaptee = ProcessingFactory::GetInstance().CreateSafe(className);
Index: CLAM/src/Flow/Networks/Network.cxx
===================================================================
--- CLAM/src/Flow/Networks/Network.cxx	(revision 11459)
+++ CLAM/src/Flow/Networks/Network.cxx	(working copy)
@@ -61,7 +61,13 @@
 			const std::string & name = it->first;
 			if (!ifHasSelectionAndContains(name))
 				continue;
-			ProcessingDefinitionAdapter procDefinition(proc, name);
+			std::string procPos="";
+			if (!_processingsBoxesPositions.empty())
+				procPos=_processingsBoxesPositions.find(name)->second;
+			std::string procSize="";
+			if(!_processingsBoxesSizes.empty())
+				procSize=_processingsBoxesSizes.find(name)->second;
+			ProcessingDefinitionAdapter procDefinition(proc, name, procPos, procSize);
 			XMLComponentAdapter xmlAdapter(procDefinition, "processing", true);
 			storage.Store(xmlAdapter);
 		}
@@ -131,6 +137,8 @@
 			}
 		}
 		_selectedProcessings.clear();
+		_processingsBoxesPositions.clear();
+		_processingsBoxesSizes.clear();
 	}
 
 	void Network::LoadFrom( Storage & storage)
@@ -146,19 +154,25 @@
 			ProcessingDefinitionAdapter procDefinition;
 			XMLComponentAdapter xmlAdapter(procDefinition, "processing", true);
 			if(storage.Load(xmlAdapter) == false) break;
+			std::string name=procDefinition.GetName();
 			
 			if (!_setPasteMode)
-				AddProcessing(procDefinition.GetName(), procDefinition.GetProcessing()); 
+				AddProcessing(name, procDefinition.GetProcessing()); 
 			else
 			{
-				const std::string & name = procDefinition.GetName();
 				CLAM::Processing * processing =procDefinition.GetProcessing();
 				std::string key=processing->GetClassName();
 				std::string newName= AddProcessing(key);
 				CLAM::Processing & newProcessing = GetProcessing(newName);
 				newProcessing.Configure(processing->GetConfig());
 				newProcNames.insert(changeProcNames::value_type(name,newName));
+				name=newName;
 			}
+			// if exists restore canvas processings boxes related attributes
+			if (procDefinition.GetPos()!="")
+				_processingsBoxesPositions.insert(ProcAttributesMap::value_type(name,procDefinition.GetPos()));
+			if (procDefinition.GetSize()!="")
+				_processingsBoxesSizes.insert(ProcAttributesMap::value_type(name,procDefinition.GetSize()));
 		}
 
 		while(1)
@@ -232,6 +246,38 @@
 		return 1;
 	}
 
+	bool Network::UpdateProcBoxesPos (const ProcAttributesMap & processingsBoxesPositions)
+	{
+		_processingsBoxesPositions.clear();
+		if (processingsBoxesPositions.empty())
+			return 1;
+		_processingsBoxesPositions=processingsBoxesPositions;
+		return 0;
+	}
+
+	bool Network::UpdateProcBoxesSizes (const ProcAttributesMap & processingsBoxesSizes)
+	{
+		_processingsBoxesSizes.clear();
+		if (processingsBoxesSizes.empty())
+			return 1;
+		_processingsBoxesSizes=processingsBoxesSizes;
+		return 0;
+	}
+
+	const Network::ProcAttributesMap Network::getProcBoxesPos()
+	{
+		const ProcAttributesMap copyProcBoxesPos(_processingsBoxesPositions);
+		_processingsBoxesPositions.clear();
+		return copyProcBoxesPos;
+	}
+
+	const Network::ProcAttributesMap Network::getProcBoxesSizes()
+	{
+		const ProcAttributesMap copyProcBoxesSizes(_processingsBoxesSizes);
+		_processingsBoxesSizes.clear();
+		return copyProcBoxesSizes;
+	}
+
 	void Network::AddFlowControl(FlowControl* flowControl)
 	{
 		if (_flowControl) delete _flowControl;
Index: CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.hxx
===================================================================
--- CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.hxx	(revision 11459)
+++ CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.hxx	(working copy)
@@ -36,12 +36,16 @@
 private:
 	Processing * mAdaptee;
 	Text mName;
+	Text mPos;
+	Text mSize;
 
 public:
-	ProcessingDefinitionAdapter( Processing * adaptee = 0, const std::string & name = "");
+	ProcessingDefinitionAdapter( Processing * adaptee = 0, const std::string & name = "", const std::string & pos = "" , const std::string & size = "");
 	virtual ~ProcessingDefinitionAdapter();	
 	Processing * GetProcessing(){return mAdaptee;}
 	const std::string & GetName(){return mName;}
+	const std::string & GetPos(){return mPos;}
+	const std::string & GetSize(){return mSize;}
 
 public:
 	//* Returns the class name
Index: CLAM/src/Flow/Networks/Network.hxx
===================================================================
--- CLAM/src/Flow/Networks/Network.hxx	(revision 11459)
+++ CLAM/src/Flow/Networks/Network.hxx	(working copy)
@@ -49,6 +49,7 @@
 	typedef std::map< std::string, Processing* > ProcessingsMap;
 	typedef std::list<std::string> NamesList;
 	typedef std::list<InPortBase *> InPortsList;
+	typedef std::map<std::string, std::string> ProcAttributesMap;
 	
 	// constructor / destructor
 	Network();
@@ -80,6 +81,12 @@
 	bool UpdateSelections (const NamesList & processingsNamesList);
 	void setPasteMode() { _setPasteMode=true; }
 
+	bool UpdateProcBoxesPos (const ProcAttributesMap & processingsBoxesPositions);
+	bool UpdateProcBoxesSizes (const ProcAttributesMap & processingsBoxesSizes);
+	const ProcAttributesMap getProcBoxesPos();
+	const ProcAttributesMap getProcBoxesSizes();
+
+
 	// methods related to connect/disconnect interface
 	bool ConnectPorts( const std::string &, const std::string & );
 	bool ConnectControls( const std::string &, const std::string & );
@@ -171,6 +178,10 @@
 	
 	bool ifHasSelectionAndContains(const std::string & name) const;
 
+	// attributes for canvas procesisngs boxes positions and sizes
+	mutable ProcAttributesMap _processingsBoxesPositions;
+	mutable ProcAttributesMap _processingsBoxesSizes;
+
 };
 
 }// namespace
_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel

Reply via email to