00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "controler-gmap.hh"
00026 using namespace std;
00027 using namespace GMap3d;
00028
00029 ostringstream* CControlerGMap::saveModel()
00030 {
00031 updateModelIfNeeded ();
00032 updateSelectionIfNeeded();
00033
00034 ostream* os;
00035 string filename = getFilename(getNewFileIndex());
00036
00037 if (FUndoOnFile)
00038 os = new ofstream(filename.c_str());
00039 else
00040 os = new ostringstream;
00041
00042 assert( os!=NULL );
00043
00044 int nbLevels = getNbSelectionLevels();
00045 int* lasts = new int[nbLevels];
00046
00047 int i,j;
00048
00049
00050 for (i=0; i<nbLevels; ++i)
00051 lasts[i] = -1;
00052
00053 CDynamicCoverageAll it(FMap);
00054
00055 for (i=0; it.cont(); ++it, ++i)
00056 for (j=0; j<nbLevels; ++j)
00057 if (*it == getLastSelectedDart(j))
00058 lasts[j] = i;
00059
00060
00061 for (i=0; i<nbLevels; ++i)
00062 (*os) << lasts[i] << " ";
00063
00064
00065 (*os) << FLastOperation << " ";
00066
00067
00068 if (! FMap->save(*os, BinaryFormat))
00069 assert(false);
00070
00071 delete [] lasts;
00072
00073 ostringstream * res;
00074
00075 if (FUndoOnFile)
00076 {
00077 os->flush();
00078 delete os;
00079 res = new ostringstream;
00080 (*res) << filename;
00081 }
00082 else
00083 res = static_cast<ostringstream*>(os);
00084
00085 return res;
00086 }
00087
00088 bool CControlerGMap::loadModel(ostringstream * AStream)
00089 {
00090 istream * is;
00091
00092 if (FUndoOnFile)
00093 {
00094 string temp = AStream->str();
00095
00096 is = new ifstream(temp.c_str());
00097 if (!is->good())
00098 {
00099 delete is;
00100 return false;
00101 }
00102 }
00103 else
00104 is = new istringstream(AStream->str());
00105
00106 int nbLevels = getNbSelectionLevels();
00107 int* lasts = new int[nbLevels];
00108 int i,k,n;
00109
00110
00111 for (i=0; i<nbLevels; ++i)
00112 (*is) >> lasts[i];
00113
00114
00115 (*is) >> FLastOperation;
00116
00117 is->get();
00118
00119 FMap->removeAllDarts();
00120
00121 setModelChanged ();
00122 setSelectionChanged();
00123
00124 for (i=0; i<nbLevels; ++i)
00125 unsetLastSelectedDart(i);
00126
00127
00128 if ( FMap->load(*is, BinaryFormat)==NULL )
00129 {
00130 FMap->removeAllDarts();
00131 delete [] lasts;
00132 delete is;
00133 return false;
00134 }
00135
00136 CDynamicCoverageAll it(FMap);
00137
00138 for (n=0; it.cont(); ++it)
00139 ++n;
00140
00141 for (i=0, it.reinit(); it.cont(); ++it, ++i)
00142 for (k=0; k<nbLevels; ++k)
00143 if (lasts[k] == n-i-1)
00144 selectDart(*it, k);
00145
00146 delete [] lasts;
00147 delete is;
00148
00149 assert(FMap->checkTopology());
00150 assert(FMap->checkEmbeddings(ORBIT_VERTEX, ATTRIBUTE_VERTEX, true));
00151
00152 return true;
00153 }
00154