[Kst] branches/work/kst/portto4/kst/src/libkstapp

Nicolas Brisset nicolas.brisset at eurocopter.com
Fri Oct 1 17:19:12 CEST 2010


SVN commit 1181634 by brisset:

Improve the algorithm: it now handles data objects before curves, and considers
the output vectors of data objects as input vectors of possible dependents so
that everybody shoould get updated properly. The only problem is that they don't
:-( 
I'm testing with one curve (2 vectors) from one file with an equation creating
two more vectors and another curve. I'm a bit puzzled, it seems that
newDataObject->replaceDependency is not working as the duplicated equation seems
to still be using the original vectors. Then, it seems that the curve created
from the equations is not in the list of relations... I have to investigate why, but I wouldn't
mind some help :-)
This is actually pretty tricky. And I haven't even started to handle matrices and
the other new types (strings, scalars)!


 M  +32 -20    changefiledialog.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/changefiledialog.cpp #1181633:1181634
@@ -411,7 +411,38 @@
 
 
 void ChangeFileDialog::duplicateDerivedObjects(QMap<DataVectorPtr, DataVectorPtr> duplicatedVectors, QMap<DataMatrixPtr, DataMatrixPtr> duplicatedMatrices, QMap<RelationPtr, RelationPtr> &duplicatedRelations) {
-  // First, take care of curves ("relations")
+  // First, data objects (equations, etc...) so that curves derived from them can be handled in the next step.
+  // Dependencies between data objects should be handled fine, assuming that when we iterate the list we get dependents after what they depend on.
+  QMap<DataObjectPtr, DataObjectPtr> duplicatedDataObjects;
+  DataObjectList dataObjects = _store->getObjects<DataObject>();
+  foreach(DataObjectPtr dataObject, dataObjects) {
+    dataObject->readLock();
+    bool dataObjectDuplicated = false;
+    DataObjectPtr newDataObject = NULL;
+    foreach(VectorPtr inputVector, dataObject->inputVectors().values()) {
+      if (duplicatedVectors.value(kst_cast<DataVector>(inputVector))) {
+        if (!dataObjectDuplicated) {
+          newDataObject = dataObject->makeDuplicate();
+          if (newDataObject) duplicatedDataObjects[dataObject] = newDataObject;
+          dataObjectDuplicated = true;
+        }
+        if (newDataObject) { // For the others, substitute the duplicated vector to be used in the duplicated relation
+          // TODO: Shouldn't we lock the object before making changes?
+          newDataObject->replaceDependency(inputVector, duplicatedVectors[kst_cast<DataVector>(inputVector)]);
+        }
+      }
+    }
+    // If we have created a new data object, its output vectors could be the inputs of further objects, so we store
+    // the mapping of old to new output vectors to be able to clone dependents later in the chain.
+    // I'm assuming the order of output vectors has not changed during the replication.
+    if (newDataObject) {
+      for(int i=0; i<dataObject->outputVectors().count(); ++i) {
+        duplicatedVectors[kst_cast<DataVector>(dataObject->outputVectors().values()[i])] = kst_cast<DataVector>(newDataObject->outputVectors().values()[i]);
+      }
+    }
+    dataObject->unlock();
+  }
+  // Now, take care of curves ("relations")
   RelationList relations = _store->getObjects<Relation>();
   foreach(RelationPtr relation, relations) {
     relation->readLock();
@@ -430,26 +461,7 @@
     }
     relation->unlock();
   }
-  // Now data objects (equations, etc...)
-  DataObjectList dataObjects = _store->getObjects<DataObject>();
-  foreach(DataObjectPtr dataObject, dataObjects) {
-    dataObject->readLock();
-    bool dataObjectDuplicated = false;
-    DataObjectPtr newDataObject = NULL;
-    foreach(VectorPtr inputVector, dataObject->inputVectors().values()) {
-      if (duplicatedVectors.value(kst_cast<DataVector>(inputVector))) {
-        if (!dataObjectDuplicated) {
-          newDataObject = dataObject->makeDuplicate();
-          dataObjectDuplicated = true;
         }
-        if (newDataObject) { // For the others, substitute the duplicated vector to be used in the duplicated relation
-            newDataObject->replaceDependency(inputVector, duplicatedVectors[kst_cast<DataVector>(inputVector)]);
-        }
-      }
-    }
-    dataObject->unlock();
-  }
-}
 
 
 }


More information about the Kst mailing list