From 3fb762e7042d9b4a1cf78556ad9ed7f117cc53ba Mon Sep 17 00:00:00 2001
From: stephane Domas <stephane.domas@univ-fcomte.fr>
Date: Thu, 3 May 2018 21:15:04 +0200
Subject: [PATCH] moved clocks list to graph

---
 AbstractInterface.cpp         |   2 +-
 AbstractInterface.h           |   3 +--
 BlockLibraryWidget.cpp        |   9 +++++----
 Dispatcher.cpp                |  17 +++++++++--------
 Dispatcher.h                  |   2 +-
 Graph.cpp                     |  12 ++++++++----
 Graph.h                       |  10 +++++++++-
 MainWindow.cpp                |   2 +-
 NewProjectDialog.cpp          |   2 +-
 Parameters.cpp                |  13 ++++++++++---
 Parameters.h                  |   6 +++---
 SpecialBlock.cpp              |   2 +-
 blast.creator.user            |   6 +++---
 lib/implementations/impls.bmf | Bin 6865 -> 6865 bytes
 lib/references/references.bmf | Bin 21656 -> 21652 bytes
 15 files changed, 53 insertions(+), 33 deletions(-)

diff --git a/AbstractInterface.cpp b/AbstractInterface.cpp
index 3295dc8..d040598 100644
--- a/AbstractInterface.cpp
+++ b/AbstractInterface.cpp
@@ -5,7 +5,7 @@
 
 AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
 
-  owner = _owner;
+  owner = _owner;  
   name = "";
   width = "1";
   direction = Input;
diff --git a/AbstractInterface.h b/AbstractInterface.h
index 8a509fb..1e208bf 100644
--- a/AbstractInterface.h
+++ b/AbstractInterface.h
@@ -91,8 +91,7 @@ protected:
   int direction;
   int type;
   QString width;
-  int endianess;
-
+  int endianess;  
 
   AbstractBlock* owner;
   /*!
diff --git a/BlockLibraryWidget.cpp b/BlockLibraryWidget.cpp
index d80a78e..32012c5 100644
--- a/BlockLibraryWidget.cpp
+++ b/BlockLibraryWidget.cpp
@@ -1,5 +1,6 @@
 #include "BlockLibraryWidget.h"
 #include "BlockLibraryTree.h"
+#include "Graph.h"
 
 BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
                                        Parameters* _params,
@@ -31,7 +32,7 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
 
 
   QString msg = "Connect to main clock/rst ext_clk/reset_0 (";
-  msg += QString::number(params->clocks.at(0));
+  msg += QString::number(params->getGraph()->getClock(0));
   msg += ")";
   radAutoClk = new QRadioButton(msg);
   radChooseClk = new QRadioButton("Choose among available clk/rst");
@@ -198,7 +199,7 @@ void BlockLibraryWidget::updateBoxConn() {
     //enableAvailableClocks(true);
   }
   QString msg = "Auto-connect to main clk/rst (ext_clk_0 at ";
-  msg += QString::number(params->clocks.at(0));
+  msg += QString::number(params->getGraph()->getClock(0));
   msg += " MHz)";
   radAutoClk->setText(msg);
 }
@@ -243,7 +244,7 @@ void BlockLibraryWidget::updateClkRst(int idCat, int idBlock) {
     comboClkGen[i] = new QComboBox();
     QString name = "";
     int id = 0;
-    foreach(double d, params->clocks) {
+    foreach(double d, params->getGraph()->getClocks()) {
       name = "ext_clk_"+QString::number(id)+" (";
       name += QString::number(d) + " MHz)";
       comboClkGen[i]->addItem(name);
@@ -255,7 +256,7 @@ void BlockLibraryWidget::updateClkRst(int idCat, int idBlock) {
   for(int i=0;i<lstRst.size();i++) {
     comboRstGen[i] = new QComboBox();
     QString name = "";
-    for(int j=0;j<params->clocks.size();j++) {
+    for(int j=0;j<params->getGraph()->getClocks().size();j++) {
       name = "ext_rst_"+QString::number(j);
       comboRstGen[i]->addItem(name);
     }
diff --git a/Dispatcher.cpp b/Dispatcher.cpp
index c50270c..b162559 100644
--- a/Dispatcher.cpp
+++ b/Dispatcher.cpp
@@ -684,7 +684,7 @@ void Dispatcher::addClkRstGenBlock(Context context, double frequency) {
 
   if (context == Design) {
 
-    params->clocks.append(frequency);
+    params->getGraph()->addClock(frequency);
 
     // get the top group
     GroupBlock *group = params->getGraph()->getTopGroup();
@@ -695,7 +695,7 @@ void Dispatcher::addClkRstGenBlock(Context context, double frequency) {
     FunctionalBlock* newOne = params->getGraph()->createFunctionalBlock(group, ref, true);
 
     QString name = "clkrstgen_";
-    name += QString::number(params->clocks.size()-1);
+    name += QString::number(params->getGraph()->getClocks().size()-1);
     newOne->setName(name);
 
     // creating the box item
@@ -704,8 +704,8 @@ void Dispatcher::addClkRstGenBlock(Context context, double frequency) {
 
     ConnectedInterface* fromIfaceClk = NULL;
     ConnectedInterface* fromIfaceReset = NULL;
-    QString clkName = "ext_clk_"+QString::number(params->clocks.size()-1);
-    QString rstName = "ext_reset_"+QString::number(params->clocks.size()-1);
+    QString clkName = "ext_clk_"+QString::number(params->getGraph()->getClocks().size()-1);
+    QString rstName = "ext_reset_"+QString::number(params->getGraph()->getClocks().size()-1);
     fromIfaceClk = new GroupInterface(group,clkName, AbstractInterface::Input, AbstractInterface::Clock);
     fromIfaceReset = new GroupInterface(group,rstName, AbstractInterface::Input, AbstractInterface::Reset);
     group->addInterface(fromIfaceClk);
@@ -737,7 +737,7 @@ void Dispatcher::addClkRstGenBlock(Context context, double frequency) {
 
 
 
-GroupWidget *Dispatcher::createTopScene(Context context){
+GroupWidget *Dispatcher::createTopScene(Context context, double mainClock){
   static QString fctName = "Dispatcher::createTopScene()";
 #ifdef DEBUG_FCTNAME
   cout << "call to " << qPrintable(fctName) << endl;
@@ -748,7 +748,8 @@ GroupWidget *Dispatcher::createTopScene(Context context){
     createIfaces = false;
   }
   // creating the graph and thus, the topgroup
-  Graph* graph = params->createGraph(createIfaces);
+  Graph* graph = params->initGraph(createIfaces);
+  graph->addClock(mainClock);
   // get the top group
   GroupBlock *topBlock = graph->getTopGroup();
   // creating the top group widget
@@ -771,8 +772,8 @@ GroupWidget *Dispatcher::createTopScene(Context context){
 
   if (context == Design) {
     // create clkrstgen
-    double freq = params->clocks.at(0);
-    params->clocks.clear();
+    double freq = params->getGraph()->getClock(0);
+    params->getGraph()->resetClocks();
     addClkRstGenBlock(context,freq);
   }
 
diff --git a/Dispatcher.h b/Dispatcher.h
index cf14b6a..46db9b5 100644
--- a/Dispatcher.h
+++ b/Dispatcher.h
@@ -75,7 +75,7 @@ public:
   void setSceneCounter(Context context, int value);
   // testers
   // others
-  GroupWidget* createTopScene(Context context);
+  GroupWidget* createTopScene(Context context, double mainClock = 0.0);
   GroupWidget* createChildScene(Context context, GroupWidget* parentWidget, BoxItem* upperItemOfGroupItem = NULL);
   void destroyScene(Context context, GroupScene* scene);
   GroupWidget *addNewEmptyGroup(Context context, GroupScene *scene, bool show = true);
diff --git a/Graph.cpp b/Graph.cpp
index 4b22691..8e55077 100644
--- a/Graph.cpp
+++ b/Graph.cpp
@@ -4,10 +4,8 @@
 #include "FunctionalBlock.h"
 #include "SpecialBlock.h"
 
-Graph::Graph(bool createTopGroupIface) {
-  topGroup = new GroupBlock(NULL, createTopGroupIface);
-  topGroup->setName("top group");
-  groups.append(topGroup);
+Graph::Graph() {
+  topGroup = NULL;
 }
 
 Graph::~Graph() {
@@ -15,6 +13,12 @@ Graph::~Graph() {
   delete topGroup;
 }
 
+void Graph::createTopGroup(bool createTopGroupIfaces) {
+  topGroup = new GroupBlock(NULL, createTopGroupIfaces);
+  topGroup->setName("top group");
+  groups.append(topGroup);
+}
+
 QList<AbstractInterface *> Graph::getOutsideInterfaces() {
   return topGroup->getInterfaces();
 }
diff --git a/Graph.h b/Graph.h
index 58690c9..d5b15a9 100644
--- a/Graph.h
+++ b/Graph.h
@@ -19,13 +19,18 @@ using namespace Qt;
 class Graph {
 
 public:
-  Graph(bool createTopGroupIface = true);
+  Graph();
   ~Graph();
 
   // getters  
   inline GroupBlock* getTopGroup() { return topGroup; }
   inline QList<GroupBlock*> getAllGroups() { return groups; }
+  inline double getClock(int id) { return clocks.at(id); }
+  inline QList<double>& getClocks() { return clocks; }
   
+  //setters
+  inline void resetClocks() { clocks.clear(); }
+
   // methods for group blocks
   GroupBlock* createChildGroupBlock(GroupBlock* parent, bool createGroupIface = true);
   void removeGroupBlock(GroupBlock *group);
@@ -44,6 +49,8 @@ public:
   bool removeStimuliBlock(FunctionalBlock* block);
   
   // others
+  void createTopGroup(bool createTopGroupIfaces = true);
+  inline void addClock(double freq) { clocks.append(freq); }
   QList<AbstractInterface *> getOutsideInterfaces();
   QList<QString> getExternalResources(); // returns the list of all external files needed for VHDL generation
 
@@ -63,6 +70,7 @@ private:
   GroupBlock* topGroup;
   QList<GroupBlock *> groups; //! usefull to avoid recursive methods to find a particular group.
   QList<FunctionalBlock*> stimulis; //! source for the top group
+  QList<double> clocks; // clocks[0] is the main clock.
 
 };
 
diff --git a/MainWindow.cpp b/MainWindow.cpp
index 8169dd0..99f13bb 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -345,7 +345,7 @@ void MainWindow::slotNewProject(){
   if (ret == 1) {
     enableProjectActions(true, PROJECT_CLOSE | PROJECT_SAVE | PROJECT_SAVEAS | PROJECT_LIB, OP_RAZ);
     enableAnalysisActions(true, ANALYSIS_ANALYZE | ANALYSIS_GENERATE, OP_RAZ);
-    GroupWidget* topGroup = dispatcher->createTopScene(Dispatcher::Design);
+    GroupWidget* topGroup = dispatcher->createTopScene(Dispatcher::Design, params->mainClock);
     addTopGroup(topGroup);
     library->updateComboScene();
     library->updateBoxConn();
diff --git a/NewProjectDialog.cpp b/NewProjectDialog.cpp
index beed427..d8e72f6 100644
--- a/NewProjectDialog.cpp
+++ b/NewProjectDialog.cpp
@@ -71,7 +71,7 @@ void NewProjectDialog::checkBeforeAccept() {
   //cout << "all ok" << endl;
   params->projectPath = dirProjEdit->text();
   params->projectFile = params->projectPath + "/" + params->projectName + ".xml";
-  params->clocks.append(freq);
+  params->mainClock = freq;
   if (autoConnClkCheck->isChecked()) {
     params->autoConnMainClk = true;
   }
diff --git a/Parameters.cpp b/Parameters.cpp
index 1195f51..d7621d2 100644
--- a/Parameters.cpp
+++ b/Parameters.cpp
@@ -52,6 +52,8 @@ Parameters::Parameters() {
   projectPath = "";
   projectName = "";
   projectFile = "";
+
+  graph = new Graph();
 }
 
 Parameters::~Parameters() {
@@ -69,8 +71,8 @@ void Parameters::clear() {
   refPathes.clear();
 }
 
-Graph* Parameters::createGraph(bool createTopGroupIfaces) {
-  graph = new Graph(createTopGroupIfaces);
+Graph* Parameters::initGraph(bool createTopGroupIfaces) {
+  graph->createTopGroup(createTopGroupIfaces);
   return graph;
 }
 
@@ -158,7 +160,7 @@ double Parameters::getFeedingClockFrequency(AbstractInterface *iface) {
       }
     }
   }
-  return clocks.at(idClock);
+  return graph->getClock(idClock);
 }
 
 void Parameters::createDelayBlock() {
@@ -346,6 +348,11 @@ GroupWidget *Parameters::loadProject(QDomElement root) throw(Exception) {
     else {
       cout << "trying to create scene n°" << idScene << " with upper scene n°" <<idUpperScene << endl;
       GroupScene* upperScene = searchSceneById(idUpperScene, topScene);
+      /* IMPORTANT: calling addNewEmptyGroup() leads to create a new GroupWidget
+       *            AND a BoxItem in upperScene that represents the GroupItem in the
+       *            newly created child scene. Thus, it has not to be created when
+       *            reading bi_group tags in the following but just searched
+       */
       groupWidget = dispatcher->addNewEmptyGroup(Dispatcher::Load, upperScene,false);
       groupWidget->getScene()->setId(idScene);
       groupItem = groupWidget->getScene()->getGroupItem();      
diff --git a/Parameters.h b/Parameters.h
index bf679fc..e14b3fe 100644
--- a/Parameters.h
+++ b/Parameters.h
@@ -138,10 +138,10 @@ public :
   QString projectPath;
   QString projectName;
   QString projectFile; // equals to projectPath/projectName.xml
-  bool autoConnMainClk; // true if auto-connection to main clock (i.e. ext_clk)
-  QList<double> clocks; // clocks[0] is the main clock.
+  bool autoConnMainClk; // true if auto-connection to main clock (i.e. ext_clk) 
+  double mainClock; // main clock freq (reported in graph->clocks(0))
 
-  Graph* createGraph(bool createTopGroupIfaces = true);
+  Graph* initGraph(bool createTopGroupIfaces = true);
   void destroyGraph();
   inline Graph* getGraph() { return graph; }  
   ReferenceBlock* getReferenceBlock(int idCategory, int idBlock); // get the reference block from its category and index
diff --git a/SpecialBlock.cpp b/SpecialBlock.cpp
index 8f2271d..fdec328 100644
--- a/SpecialBlock.cpp
+++ b/SpecialBlock.cpp
@@ -104,7 +104,7 @@ void SpecialBlock::computeOutputPatternClockConvert(int nbExec) throw(Exception)
    */
   AbstractInterface* clkIn = getIfaceFromName("clk_in");
   AbstractInterface* clkOut = getIfaceFromName("clk_out");
-  cout << "freq clk_in = " << clkIn-
+  //cout << "freq clk_in = " << clkIn-
 
   // in case of inputPattern not created, do it
   if (lengthIP <= 0) {
diff --git a/blast.creator.user b/blast.creator.user
index b2e76dd..7270400 100644
--- a/blast.creator.user
+++ b/blast.creator.user
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.2.0, 2018-05-03T17:24:00. -->
+<!-- Written by QtCreator 4.2.0, 2018-05-03T21:14:33. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
-  <value type="QByteArray">{3701e197-5b6c-48ea-9e98-a6cf6de18672}</value>
+  <value type="QByteArray">{c8006d66-d34f-42be-ad10-d0207752286d}</value>
  </data>
  <data>
   <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -61,7 +61,7 @@
   <valuemap type="QVariantMap">
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
-   <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{ed04208c-8774-456b-99b9-4a02094ca7a4}</value>
+   <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{2c9bf876-3476-44eb-8065-1f0844704dda}</value>
    <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
    <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
    <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
diff --git a/lib/implementations/impls.bmf b/lib/implementations/impls.bmf
index 31ec0a1a87da3f8be4fd98d9f4f0e3556672e735..3fc15fe88cb31a5ae83e427ff9f1f830fa797dd8 100644
GIT binary patch
delta 63
zcmV-F0KoszHPJP&FAbA}4Iq<G4GIA>lK})1lWh$alUWTQv!e~<0+a0!WRryuW|L77
V?~{ZQ7?XMu3X?z*I<uS-H3+E)6(#@x

delta 59
zcmV-B0L1^%HPJP&FAbAf4N8+w4GIA<lK})1lWh$Qv!e~<0+a0!WRryuW|L77?~`H@
RI+J=53X?z*7_*!bH3(oa6W;&;

diff --git a/lib/references/references.bmf b/lib/references/references.bmf
index b7a6ef6d9acaa1b455b30970d8800f9d287577d9..ffc13f1aabbedeaed3d3a625235c20a55bfb292b 100644
GIT binary patch
delta 239
zcmbQSl5xsPMivH!kO>=EqPZCRHYacuGTNswSTdx5VIo5+g9(EfgE4~zLo!g*jKP#4
zi6IRLlY#Q4K-vUIg2WRU41i)5K#|nR0z9gm91KN3y@?Dto85Tg`5AdOFO%NSXm1YG
zl>{^`k-;2Dn*w19P=^IjKS&g0OA?T60=6>+s2>E)fH)0E0$nxPAxLuaUfCw*OoqJ4
w1#*h4d_X&MCKpJHPp*|)2Npe`8anx<j}$*xh9R3Fo*|#1l%ZtvD*1ON0HGN)00000

delta 229
zcmW+vy9&ZU5S+sl5+YhyDH;UrqnC%Ng5RK43cg|*ZM3oS3oI{)s8|Y?a;@MWiJ#yY
zmffA3*_lfp;`9&(Fi4-q$P`CCH8&#iv4DdaXMzAeaR*(ZIXMRs?Mz*Adb~);dSp9r
z5wjCjvRbO&EbE>%E{eRqRo^0V>36ex$t<50(Ah@FUwkIVObEFhqJ)={yUSO=a+rCo
pU2<E*>MI)si=H)Bm|%zPpHYYUIa6P)q1xLORkh6=HGQ`~?hhyWF*X1I

-- 
2.39.5