El 06/11/2008 06:03 PM, David García Garzón escribió:
About the position/size question. If we have a solution let's implement it.
But if not, meanwhile, to have the cut&paste working properly without
breaking the format we could just use the positions when cutting or pasting
and ignore or set them empty on loading and storing.
Related to the patch but unrelated to the discussion. I did some enhancements
on the qaction handling. Mainly i used the canvas member actions you added as
the actions in the context menu. (Not with the remove action which have
different semantics with the context menu one, by now). This way we are
getting the shortcuts whenever we see the menu. I also enabled the
translation of menu options text by using tr("text"), changed the 'Copy
Processing(s)' and so on to a bare standard 'Copy' and added some icons from
kde 3.5 standard set.
Very nice. I like it, and the icons :)
By having persistent actions, in the future, but not an urgent need, the
MainWindow could ask the canvas for actions to insert at the edit menu and
the canvas could enable or disable them according to the selection or the
clipboard. :-)
I agree.
Well, sorry for the late patch. I was quite busy with other things, and
in the middle thinking and testing different types and ways to pass the
data between classes.
Here is my actual solution (which I don't know if it's so good): I made
a subclass of network: ProcessingGeometry[1]. I think maybe it would be
simpler with just a structure, or putting it on other place
(Processing?). Any critic is welcome.
On MainWindow I added a line to load the geometries from the XML, and if
it fails try with the .pos file.
I would need to add a checkbox when saving, to select what format do you
want. By now, it write only the traditional .pos file (for development
testings you can paste the clipboard after copy / paste to a file, and
load it).
Regards,
Natanael.
[1] The CLAM::Network::ProcessingGeometry class:
class ProcessingGeometry //TODO: maybe just define a struct?
{
public:
void getPosition(int & x,int & y) const
{ x =_x; y =_y; }
const std::string getPosition() const
{ return IntsToString(_x,_y); }
void getSize (int & w,int & h) const
{ w =_w; h =_h; }
const std::string getSize() const
{ return IntsToString(_w,_h); }
void setPosition (int x, int y)
{_x=x;_y=y;}
void setPosition(const std::string & positionString) {
StringPairToInts(positionString,_x,_y);}
void setSize (int w, int h)
{_w=w;_h=h;}
void setSize(const std::string & sizeString) {
StringPairToInts(sizeString,_w,_h);}
private:
int _x,_y,_w,_h;
void StringPairToInts(const std::string & geometryInString, int
& a, int & b)
{
a=atoi(geometryInString.substr(0,geometryInString.find(",")).c_str());
b=atoi(geometryInString.substr(geometryInString.find(",")+1,geometryInString.length()).c_str());
}
const std::string IntsToString (const int & a, const int & b) const
{
std::ostringstream stream;
stream<<a<<","<<b;
return stream.str();
}
};
typedef std::map <std::string, ProcessingGeometry>
ProcessingsGeometryMap;
Index: NetworkEditor/src/MainWindow.hxx
===================================================================
--- NetworkEditor/src/MainWindow.hxx (revision 11500)
+++ NetworkEditor/src/MainWindow.hxx (working copy)
@@ -209,7 +209,9 @@
return;
}
_canvas->loadNetwork(&_network);
- _canvas->loadPositions(filename+".pos");
+ // by default, try reading on XML:
+ if (!_canvas->loadGeometriesFromXML())
+ _canvas->loadPositions(filename+".pos");
appendRecentFile(filename);
_networkFile = filename;
updateCaption();
Index: NetworkEditor/src/NetworkCanvas.hxx
===================================================================
--- NetworkEditor/src/NetworkCanvas.hxx (revision 11500)
+++ NetworkEditor/src/NetworkCanvas.hxx (working copy)
@@ -1246,6 +1246,44 @@
box->resize(size);
}
}
+
+ bool updateGemometriesOnXML(QPoint offsetPoint = QPoint(0,0))
+ {
+ CLAM::Network::ProcessingsGeometryMap processingsGeometryMap;
+
+ for (unsigned i=0; i<_processings.size(); i++)
+ {
+ CLAM::Network::ProcessingGeometry processingGeometry;
+ QPoint position = _processings[i]->pos();
+ QSize size = _processings[i]->size();
+ const std::string name=_processings[i]->getName().toStdString();
+ processingGeometry.setPosition(position.x()-offsetPoint.x(),position.y()-offsetPoint.y());
+ processingGeometry.setSize(size.width(),size.height());
+ processingsGeometryMap.insert(CLAM::Network::ProcessingsGeometryMap::value_type(name,processingGeometry));
+ }
+ return (_network->UpdateProcessingsGeometry(processingsGeometryMap));
+ }
+ bool loadGeometriesFromXML(QPoint offsetPoint = QPoint(0,0))
+ {
+ const CLAM::Network::ProcessingsGeometryMap & processingsGeometryMap=_network->GetProcessingsGeometry();
+ if (processingsGeometryMap.empty())
+ return 0;
+ CLAM::Network::ProcessingsGeometryMap::const_iterator it;
+ for(it=processingsGeometryMap.begin();it!=processingsGeometryMap.end();it++)
+ {
+ QString name=QString(it->first.c_str());
+ const CLAM::Network::ProcessingGeometry & processingGeometry=it->second;
+ int x,y,w,h;
+ processingGeometry.getPosition(x,y);
+ QPoint position=offsetPoint+QPoint(x,y);
+ processingGeometry.getSize(w,h);
+ QSize size=QSize(w,h);
+ ProcessingBox * box=getBox(name);
+ box->move(position);
+ box->resize(size);
+ }
+ return 1;
+ }
private slots:
void onCopyConnection()
{
@@ -1279,9 +1317,10 @@
void onCopyProcessingsToClipboard(bool cut=false)
{
+ QPoint point = ((QAction*)sender())->data().toPoint();
std::ostringstream streamXMLBuffer;
CLAM::Network::NamesList processingsNamesList;
- // Copy selected (/active) processings on networkToCopy
+ // Copy selected processings on networkToCopy
for (unsigned i=0; i<_processings.size();i++)
{
if (!_processings[i]->isSelected())
@@ -1291,6 +1330,7 @@
}
if (_network->UpdateSelections(processingsNamesList))
return;
+ updateGemometriesOnXML(point);
CLAM::XmlStorage::Dump(*_network,"network",streamXMLBuffer);
QApplication::clipboard()->setText(QString(streamXMLBuffer.str().c_str()));
@@ -1331,6 +1371,7 @@
return;
}
reloadNetwork();
+ loadGeometriesFromXML(point);
}
@@ -1680,7 +1721,9 @@
this, SLOT(onDeleteProcessing()));
removeAction->setData(translatedPos);
removeAction->setShortcut(tr("Del"));
+ _copySelectionAction->setData(translatedPos);
menu->addAction(_copySelectionAction);
+ _cutSelectionAction->setData(translatedPos);
menu->addAction(_cutSelectionAction);
return;
}
Index: CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.cxx
===================================================================
--- CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.cxx (revision 11500)
+++ 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 & position, const std::string & size )
+ : mAdaptee(adaptee), mName(name), mPosition(position), mSize(size)
{
}
@@ -47,7 +47,18 @@
XMLAdapter<Text> classNameAdapter( className, "type");
store.Store(nameAdapter);
store.Store(classNameAdapter);
-
+ if (mPosition!="") // check if position is defined (QPoint values are integers)
+ {
+ Text positionCopy(mPosition);
+ XMLAdapter<Text> positionAdapter (positionCopy, "position");
+ store.Store(positionAdapter);
+ }
+ if (mSize!="") // check if size is defined
+ {
+ Text sizeCopy(mSize);
+ XMLAdapter<Text> sizeAdapter (sizeCopy, "size");
+ 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> positionAdapter (mPosition, "position");
+ store.Load(positionAdapter);
+ XMLAdapter<Text> sizeAdapter (mSize, "size");
+ store.Load(sizeAdapter);
+
try
{
mAdaptee = ProcessingFactory::GetInstance().CreateSafe(className);
Index: CLAM/src/Flow/Networks/Network.cxx
===================================================================
--- CLAM/src/Flow/Networks/Network.cxx (revision 11500)
+++ CLAM/src/Flow/Networks/Network.cxx (working copy)
@@ -59,9 +59,18 @@
{
Processing * proc = it->second;
const std::string & name = it->first;
- if (!ifHasSelectionAndContains(name))
+ if (!HasSelectionAndContains(name))
continue;
- ProcessingDefinitionAdapter procDefinition(proc, name);
+ std::string processingPosition;
+ std::string processingSize;
+ // if exists canvas processing boxes attributes, store them
+ if (!_processingsGeometry.empty())
+ {
+ ProcessingGeometry & geometry=_processingsGeometry.find(name)->second;
+ processingPosition=geometry.getPosition();
+ processingSize=geometry.getSize();
+ }
+ ProcessingDefinitionAdapter procDefinition(proc, name, processingPosition, processingSize);
XMLComponentAdapter xmlAdapter(procDefinition, "processing", true);
storage.Store(xmlAdapter);
}
@@ -75,7 +84,7 @@
const std::string & name = it->first;
Processing * proc = it->second;
- if (!ifHasSelectionAndContains(name))
+ if (!HasSelectionAndContains(name))
continue;
OutPortRegistry::Iterator itOutPort;
@@ -93,7 +102,7 @@
namesIterator!=namesInPorts.end();
namesIterator++)
{
- if (!ifHasSelectionAndContains(GetProcessingIdentifier(*namesIterator)))
+ if (!HasSelectionAndContains(GetProcessingIdentifier(*namesIterator)))
continue;
ConnectionDefinitionAdapter connectionDefinition( outPortName, *namesIterator );
XMLComponentAdapter xmlAdapter(connectionDefinition, "port_connection", true);
@@ -107,7 +116,7 @@
const std::string & name = it->first;
Processing * proc = it->second;
- if (!ifHasSelectionAndContains(name))
+ if (!HasSelectionAndContains(name))
continue;
OutControlRegistry::Iterator itOutControl;
@@ -122,7 +131,7 @@
namesIterator!=namesInControls.end();
namesIterator++)
{
- if (!ifHasSelectionAndContains(GetProcessingIdentifier(*namesIterator)))
+ if (!HasSelectionAndContains(GetProcessingIdentifier(*namesIterator)))
continue;
ConnectionDefinitionAdapter connectionDefinition( outControlName, *namesIterator );
XMLComponentAdapter xmlAdapter(connectionDefinition, "control_connection", true);
@@ -131,6 +140,7 @@
}
}
_selectedProcessings.clear();
+ _processingsGeometry.clear();
}
void Network::LoadFrom( Storage & storage)
@@ -140,25 +150,35 @@
if (!_setPasteMode) Clear();
XMLAdapter<std::string> strAdapter( _name, "id");
storage.Load(strAdapter);
+ _processingsGeometry.clear();
while(1)
{
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 canvas processings boxes related attributes, restore them
+ if (procDefinition.GetPosition()!="" && procDefinition.GetSize()!="")
+ {
+ ProcessingGeometry ProcessingsGeometryMap;
+ ProcessingsGeometryMap.setPosition(procDefinition.GetPosition());
+ ProcessingsGeometryMap.setSize(procDefinition.GetSize());
+ _processingsGeometry.insert(ProcessingsGeometryMap::value_type(name,ProcessingsGeometryMap));
+ }
}
while(1)
@@ -224,7 +244,7 @@
}
- bool Network::ifHasSelectionAndContains(const std::string & name) const
+ bool Network::HasSelectionAndContains(const std::string & name) const
{
NamesSet::const_iterator itFindSelected = _selectedProcessings.find(name);
if (!_selectedProcessings.empty() && itFindSelected==_selectedProcessings.end())
@@ -232,6 +252,21 @@
return 1;
}
+ bool Network::UpdateProcessingsGeometry (const ProcessingsGeometryMap & processingsGeometry)
+ {
+ _processingsGeometry.clear();
+ if (processingsGeometry.empty())
+ return 1;
+ _processingsGeometry=processingsGeometry;
+ return 0;
+ }
+ const Network::ProcessingsGeometryMap Network::GetProcessingsGeometry()
+ {
+ const ProcessingsGeometryMap copyProcessingsGeometry(_processingsGeometry);
+ _processingsGeometry.clear();
+ return copyProcessingsGeometry;
+ }
+
void Network::AddFlowControl(FlowControl* flowControl)
{
if (_flowControl) delete _flowControl;
Index: CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.hxx
===================================================================
--- CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.hxx (revision 11500)
+++ CLAM/src/Flow/Networks/ProcessingDefinitionAdapter.hxx (working copy)
@@ -36,12 +36,16 @@
private:
Processing * mAdaptee;
Text mName;
+ Text mPosition;
+ Text mSize;
public:
- ProcessingDefinitionAdapter( Processing * adaptee = 0, const std::string & name = "");
+ ProcessingDefinitionAdapter( Processing * adaptee = 0, const std::string & name = "", const std::string & position="", const std::string & size = "");
virtual ~ProcessingDefinitionAdapter();
Processing * GetProcessing(){return mAdaptee;}
const std::string & GetName(){return mName;}
+ const std::string & GetPosition(){return mPosition;}
+ 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 11500)
+++ CLAM/src/Flow/Networks/Network.hxx (working copy)
@@ -49,6 +49,39 @@
typedef std::map< std::string, Processing* > ProcessingsMap;
typedef std::list<std::string> NamesList;
typedef std::list<InPortBase *> InPortsList;
+
+ class ProcessingGeometry //TODO: maybe just define a struct?
+ {
+ public:
+ void getPosition(int & x,int & y) const
+ { x =_x; y =_y; }
+ const std::string getPosition() const
+ { return IntsToString(_x,_y); }
+ void getSize (int & w,int & h) const
+ { w =_w; h =_h; }
+ const std::string getSize() const
+ { return IntsToString(_w,_h); }
+ void setPosition (int x, int y)
+ {_x=x;_y=y;}
+ void setPosition(const std::string & positionString) { StringPairToInts(positionString,_x,_y);}
+ void setSize (int w, int h)
+ {_w=w;_h=h;}
+ void setSize(const std::string & sizeString) { StringPairToInts(sizeString,_w,_h);}
+ private:
+ int _x,_y,_w,_h;
+ void StringPairToInts(const std::string & geometryInString, int & a, int & b)
+ {
+ a=atoi(geometryInString.substr(0,geometryInString.find(",")).c_str());
+ b=atoi(geometryInString.substr(geometryInString.find(",")+1,geometryInString.length()).c_str());
+ }
+ const std::string IntsToString (const int & a, const int & b) const
+ {
+ std::ostringstream stream;
+ stream<<a<<","<<b;
+ return stream.str();
+ }
+ };
+ typedef std::map <std::string, ProcessingGeometry> ProcessingsGeometryMap;
// constructor / destructor
Network();
@@ -79,6 +112,8 @@
// methods related to copy&paste processings from canvas
bool UpdateSelections (const NamesList & processingsNamesList);
void setPasteMode() { _setPasteMode=true; }
+ bool UpdateProcessingsGeometry (const ProcessingsGeometryMap & processingsProcessingGeometry);
+ const ProcessingsGeometryMap GetProcessingsGeometry ();
// methods related to connect/disconnect interface
bool ConnectPorts( const std::string &, const std::string & );
@@ -174,8 +209,11 @@
mutable NamesSet _selectedProcessings;
bool _setPasteMode;
- bool ifHasSelectionAndContains(const std::string & name) const;
+ bool HasSelectionAndContains(const std::string & name) const;
+ // attributes for canvas processing geometries
+ mutable ProcessingsGeometryMap _processingsGeometry;
+
};
}// namespace
_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel