X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/756baf5c8eaf003e8271dab9c395de2b0e704857..a7299f808c1906872b76aa62fb6d8276096c4ff5:/Parameters.cpp

diff --git a/Parameters.cpp b/Parameters.cpp
index c60a927..2ee6255 100644
--- a/Parameters.cpp
+++ b/Parameters.cpp
@@ -46,10 +46,12 @@ Parameters::Parameters() {
 
   unsaveModif = false;
   isRstClkShown = false;
-
-  projectPath = QDir::currentPath();
   
   validityExtension = "_enb";
+
+  projectPath = "";
+  projectName = "";
+  projectFile = "";
 }
 
 Parameters::~Parameters() {
@@ -572,10 +574,27 @@ void Parameters::loadBlastConfiguration(QString confFile) throw(Exception) {
     implPathes.append(path);
     cout << "impl path : " << qPrintable(path) << endl << endl;
   }
+
+  QDomElement eltSource = eltImpl.nextSiblingElement("sources");
+  nbPathesStr = eltSource.attribute("nb","none");
+  nbPathes = nbPathesStr.toInt(&ok);
+  QDomNodeList listSourceDir = eltSource.elementsByTagName("source_lib");
+  if ((!ok) || (nbPathes != listSourceDir.size())) throw(Exception(CONFIGFILE_CORRUPTED));
+
+  for(int i=0;i<listSourceDir.size();i++) {
+    QDomNode nodeSourceDir = listSourceDir.at(i);
+    QDomElement eltSourceDir = nodeSourceDir.toElement();
+    if (eltSourceDir.isNull()) throw(Exception(CONFIGFILE_CORRUPTED));
+    QString path = eltSourceDir.attribute("path","none");
+    if (path == "none") throw(Exception(CONFIGFILE_CORRUPTED));
+    sourcePathes.append(path);
+    cout << "core path : " << qPrintable(path) << endl << endl;
+  }
+
   // getting elt = the element <defaults>
   // for each child element, initialize the associated attributes of Parameters
 
-  QDomElement eltDefaults = eltImpl.nextSiblingElement("defaults");
+  QDomElement eltDefaults = eltSource.nextSiblingElement("defaults");
 
   QDomElement eltBlocks = eltDefaults.firstChildElement("blocks");
   QString attributeStr = eltBlocks.attribute("width", "none");
@@ -805,6 +824,22 @@ void Parameters::loadImplementationsFromXml() throw(Exception) {
       QString refXml = implRoot.attribute("ref_name","none");
       QString refMd5 = implRoot.attribute("ref_md5","none");
       BlockImplementation* impl = new BlockImplementation(fileName,refXml,refMd5);
+
+      QDomNodeList archNode = implRoot.elementsByTagName("architecture");
+
+      if (archNode.isEmpty()) {
+        cout << "impl has no architecture" << endl;
+        return;
+      }
+      QDomElement archElt = archNode.at(0).toElement();
+      QString compList = archElt.attribute("comp_list","none");
+      if (compList != "none") {
+        QStringList compos = compList.split(",");
+        foreach(QString s, compos) {
+          impl->addResource(s);
+        }
+      }
+
       try {
         impl->loadPatterns(implRoot);
       }
@@ -906,6 +941,74 @@ void Parameters::saveImplementationsToLib() throw(Exception) {
   libFile.close();
 
 }
+
+
+void Parameters::loadSources() throw(Exception) {
+
+  for(int i=0;i<sourcePathes.size();i++) {
+    cout << "analyzing " << qPrintable(sourcePathes.at(i)) << endl;
+    QDir dir(sourcePathes.at(i));
+    QStringList filter;
+    filter << "*.vhd" << "*.ngc";
+    dir.setNameFilters(filter);
+    QStringList list = dir.entryList();
+    for(int j=0;j<list.size();j++) {
+      QString fileName = dir.absolutePath();
+      fileName.append("/"+list.at(j));
+
+      if (list.at(j).endsWith(".ngc")) {
+        QString netName = list.at(j);
+        netName.truncate(list.at(j).size() -4);
+        cout << "found netlist " << qPrintable(netName) << endl;
+        availableResources.append(new ExternalResource(netName,fileName,ExternalResource::Netlist));
+      }
+      else {
+        cout << "parsing " << qPrintable(fileName) << " ... ";
+        QFile srcXML(fileName);
+        if (!srcXML.open(QIODevice::ReadOnly)) {
+          throw(Exception(IMPLFILE_NOACCESS));
+        }
+        QTextStream in(&srcXML);
+
+        QString line = in.readLine();
+        while (!line.isNull()) {
+          if (line.contains("package", Qt::CaseInsensitive)) {
+            QRegularExpression rxPack("^package (.+) is$",QRegularExpression::CaseInsensitiveOption);
+            QRegularExpressionMatch matchPack = rxPack.match(line);
+            if (matchPack.hasMatch()) {
+              QString packName = matchPack.captured(1);
+              cout << "found package " << qPrintable(packName) << endl;
+              availableResources.append(new ExternalResource(packName,fileName,ExternalResource::Package));
+            }
+          }
+          else if (line.contains("entity", Qt::CaseInsensitive)) {
+            QRegularExpression rxEnt("^entity (.+) is$",QRegularExpression::CaseInsensitiveOption);
+            QRegularExpressionMatch matchEnt = rxEnt.match(line);
+            if (matchEnt.hasMatch()) {
+              QString entityName = matchEnt.captured(1);
+              cout << "found entity " << qPrintable(entityName) << endl;
+              availableResources.append(new ExternalResource(entityName,fileName,ExternalResource::Code));
+            }
+          }
+          line = in.readLine();
+        }
+        srcXML.close();
+        cout << "OK" << endl;
+      }
+    }
+  }
+}
+
+QList<ExternalResource *> Parameters::searchResourceByName(const QString& name) {
+  QList<ExternalResource*> listRes;
+  foreach(ExternalResource* s, availableResources) {
+    if (s->getName() == name) {
+      listRes.append(s);
+    }
+  }
+  return listRes;
+}
+
 void Parameters::addAvailableBlock(ReferenceBlock *block) {
   availableBlocks.append(block);
   foreach (int id,block->getCategories()) {
@@ -1222,3 +1325,10 @@ InterfaceItem* Parameters::searchInterfaceItemById(int id, GroupScene* scene) {
   }
   return NULL;
 }
+
+QString Parameters::normalizeName(const QString &name) {
+  QString s = name;
+  s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_");
+  s.replace(QRegularExpression("[_]+"),"_");
+  return s;
+}