@@ -187,6 +187,23 @@ oms_status_enu_t oms::Model::loadSnapshot(const pugi::xml_node& node)
187187 return oms_status_ok;
188188}
189189
190+ oms_status_enu_t oms::Model::duplicateVariant (const ComRef& crefA, const ComRef& crefB)
191+ {
192+ if (!crefA.isEmpty ())
193+ return logError (" only top level model is allowed" );
194+
195+ // copy the current snapshot
196+ char * fullsnapshot = NULL ;
197+ exportSnapshot (" " , &fullsnapshot);
198+
199+ listVariants.push_back (fullsnapshot);
200+
201+ // set the current variantName
202+ this ->variantName = std::string (crefB) + " .ssd" ;
203+ this ->signalFilterFilename = " resources/signalFilter_" + std::string (crefB) + " .xml" ;
204+ return oms_status_ok;
205+ }
206+
190207oms_status_enu_t oms::Model::importSnapshot (const char * snapshot_, char ** newCref)
191208{
192209 if (!validState (oms_modelState_virgin))
@@ -343,7 +360,7 @@ oms_status_enu_t oms::Model::list(const oms::ComRef& cref, char** contents)
343360 pugi::xml_node ssdNode = snapshot.getTemplateResourceNodeSSD (" SystemStructure.ssd" , this ->getCref ());
344361 pugi::xml_node system_node = ssdNode.append_child (oms::ssp::Draft20180219::ssd::system);
345362
346- subsystem->exportToSSD (system_node, snapshot);
363+ subsystem->exportToSSD (system_node, snapshot, this -> variantName );
347364 doc.append_copy (snapshot.getResourceNode (" SystemStructure.ssd" ).first_child ());
348365 }
349366 else
@@ -356,7 +373,7 @@ oms_status_enu_t oms::Model::list(const oms::ComRef& cref, char** contents)
356373 pugi::xml_node ssdNode = snapshot.getTemplateResourceNodeSSD (" SystemStructure.ssd" , this ->getCref ());
357374 pugi::xml_node system_node = ssdNode.append_child (oms::ssp::Draft20180219::ssd::system);
358375
359- component->exportToSSD (system_node, snapshot);
376+ component->exportToSSD (system_node, snapshot, this -> variantName );
360377 doc.append_copy (snapshot.getResourceNode (" SystemStructure.ssd" ).first_child ());
361378 }
362379 }
@@ -703,12 +720,12 @@ oms_status_enu_t oms::Model::addSystem(const oms::ComRef& cref, oms_system_enu_t
703720
704721oms_status_enu_t oms::Model::exportToSSD (Snapshot& snapshot) const
705722{
706- pugi::xml_node ssdNode = snapshot.getTemplateResourceNodeSSD (" SystemStructure.ssd " , this ->getCref ());
723+ pugi::xml_node ssdNode = snapshot.getTemplateResourceNodeSSD (this -> variantName , this ->getCref ());
707724
708725 if (system)
709726 {
710727 pugi::xml_node system_node = ssdNode.append_child (oms::ssp::Draft20180219::ssd::system);
711- if (oms_status_ok != system->exportToSSD (system_node, snapshot))
728+ if (oms_status_ok != system->exportToSSD (system_node, snapshot, this -> variantName ))
712729 return logError (" export of system failed" );
713730 }
714731
@@ -958,6 +975,27 @@ void oms::Model::writeAllResourcesToFilesystem(std::vector<std::string>& resourc
958975 logError (" failed to export \" " + filename + " to directory " + tempDir);
959976 }
960977
978+ // get all the variants and its resources
979+ // TODO how to handle mutiple resouces with same file name (e.g) resources/signalFilter.xml and other ssv resouces
980+ for (auto const & variant : listVariants)
981+ {
982+ std::vector<std::string> variantResources;
983+ Snapshot snapshot_;
984+ snapshot_.import (variant);
985+ snapshot_.getResources (variantResources);
986+ // snapshot_.debugPrintAll();
987+ for (auto const &variantfilename : variantResources)
988+ {
989+ // std::cout << "\n variant resources : " << variantfilename;
990+ auto file = std::find (resources.begin (), resources.end (), variantfilename);
991+ if (file == resources.end ())
992+ {
993+ resources.push_back (variantfilename);
994+ snapshot_.writeResourceNode (variantfilename, filesystem::path (tempDir));
995+ }
996+ }
997+ }
998+
961999 // export the unreferenced ssv and ssm files to ssp, this must be extended to export all unreferenced resources
9621000 for (auto & it : importedResources)
9631001 {
0 commit comments