From 230702199ca5526792eb721fca83c70439ce5189 Mon Sep 17 00:00:00 2001 From: Marek Blok <Marek.Blok@pg.edu.pl> Date: Wed, 1 Mar 2023 11:16:22 +0100 Subject: [PATCH] Added GetHtmlNodeLabel_DOTfile --- src/cpp/DSP_DOT.cpp | 89 +++++++++++++++++++++------------------ src/include/DSP_lib.h | 2 +- src/include/DSP_modules.h | 5 +++ 3 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/cpp/DSP_DOT.cpp b/src/cpp/DSP_DOT.cpp index eb0d5ce..d254c9e 100644 --- a/src/cpp/DSP_DOT.cpp +++ b/src/cpp/DSP_DOT.cpp @@ -236,7 +236,7 @@ string DSP::Component::GetComponentNodeParams_DOTfile(void) { * -# copy string segment into output buffer. * . */ -string DSP::Component::GetComponentNodeParams_DOTfile(const string &leading_space) +string DSP::Component::GetHtmlNodeLabel_DOTfile(const unsigned long &no_of_inputs, const unsigned long &no_of_outputs, const string &node_name, const string &leading_space) { string tempName; unsigned int ind; @@ -245,7 +245,7 @@ string DSP::Component::GetComponentNodeParams_DOTfile(const string &leading_spac //! length of the output text (including trailing zero) stringstream text_buffer; - tempName = GetName(); + tempName = node_name; if (tempName.length() == 0) tempName = "NONAME"; @@ -255,50 +255,27 @@ string DSP::Component::GetComponentNodeParams_DOTfile(const string &leading_spac clock_003D6808 -> mixed_2:clock [style=dotted, constraint=false, color=red]; */ - // https://graphviz.org/doc/info/shapes.html - /* - mixed_2 [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> - <TR><TD PORT="in1">in1</TD><TD PORT="in2">in2</TD></TR> - <TR><TD>DDScos</TD></TR> - <TR><TD PORT="out1">out1</TD><TD PORT="out2">out2</TD></TR> - </TABLE>>, shape=plain]; - */ - unsigned long tmp_no_of_inputs = 1, tmp_no_of_outputs = 1; - if (Convert2Block() != NULL) { - tmp_no_of_inputs = Convert2Block()->NoOfInputs; - // text_buffer << "# tmp_no_of_inputs=" << tmp_no_of_inputs << std::endl; - if (tmp_no_of_inputs == 0) tmp_no_of_inputs = 1; - tmp_no_of_outputs = Convert2Block()->NoOfOutputs; - // text_buffer << "# tmp_no_of_outputs=" << tmp_no_of_outputs << std::endl; - if (tmp_no_of_outputs == 0) tmp_no_of_outputs = 1; - } - // text_buffer << "# tmp_no_of_inputs=" << tmp_no_of_inputs << ", tmp_no_of_outputs=" << tmp_no_of_outputs << std::endl; + unsigned long tmp_no_of_inputs = no_of_inputs, tmp_no_of_outputs = no_of_outputs; + if (tmp_no_of_inputs == 0) tmp_no_of_inputs = 1; + if (tmp_no_of_outputs == 0) tmp_no_of_outputs = 1; unsigned long gcd = DSP::f::gcd(tmp_no_of_inputs, tmp_no_of_outputs); unsigned long no_of_html_columns = (tmp_no_of_inputs * tmp_no_of_outputs) / gcd; - // text_buffer << "# gcd=" << gcd << ", no_of_html_columns=" << no_of_html_columns << std::endl; unsigned long no_of_columns_per_input = no_of_html_columns / tmp_no_of_inputs; unsigned long no_of_columns_per_output = no_of_html_columns / tmp_no_of_outputs; - // text_buffer << "# no_of_columns_per_input=" << no_of_columns_per_input << ", no_of_columns_per_output=" << no_of_columns_per_output << std::endl; - text_buffer << "[label=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">" << std::endl; + // https://graphviz.org/doc/info/shapes.html + text_buffer << "label=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">" << std::endl; - if (Convert2Block() != NULL) + if (no_of_inputs > 0) { - if (Convert2Block()->NoOfInputs > 0) - { - text_buffer << leading_space << " " << "<TR>"; // \t - TAB - - for (ind =0; ind < Convert2Block()->NoOfInputs; ind++) - { - // if (ind == 0) - // text_buffer << "<in" << ind << "> "; - // else - // text_buffer << " | <in" << ind << "> "; - text_buffer << "<TD COLSPAN=\"" << no_of_columns_per_input << "\" PORT=\"in" << ind+1 << "\"><FONT POINT-SIZE=\"8.0\">in" << ind+1 << "</FONT></TD>"; - } + text_buffer << leading_space << " " << "<TR>"; // \t - TAB - text_buffer << "</TR>" << std::endl; + for (ind =0; ind < no_of_inputs; ind++) + { + text_buffer << "<TD COLSPAN=\"" << no_of_columns_per_input << "\" PORT=\"in" << ind+1 << "\"><FONT POINT-SIZE=\"8.0\">in" << ind+1 << "</FONT></TD>"; } + + text_buffer << "</TR>" << std::endl; } // prepare label @@ -334,11 +311,11 @@ string DSP::Component::GetComponentNodeParams_DOTfile(const string &leading_spac text_buffer << leading_space << " " << "<TR><TD COLSPAN=\"" << no_of_html_columns << "\">" << internal_text << "</TD></TR>" << std::endl; - if (NoOfOutputs > 0) + if (no_of_outputs > 0) { text_buffer << leading_space << " " << "<TR>"; // \t - TAB - for (ind =0; ind < NoOfOutputs; ind++) + for (ind =0; ind < no_of_outputs; ind++) { // if (ind == 0) // text_buffer << "<out" << ind << "> "; @@ -351,6 +328,38 @@ string DSP::Component::GetComponentNodeParams_DOTfile(const string &leading_spac } text_buffer << leading_space << " " << "</TABLE>>, shape=plain"; + return text_buffer.str(); +} + +// Returns component node parameters used in DOTfile +/* + * -# generate string segment (internal buffer - ?? size selection) + * -# check if it will fit into the output buffer + * -# copy string segment into output buffer. + * . + */ +string DSP::Component::GetComponentNodeParams_DOTfile(const string &leading_space) +{ + string tempName; + //! pointer to an internal text buffer + string internal_text; + //! length of the output text (including trailing zero) + stringstream text_buffer; + + tempName = GetName(); + if (tempName.length() == 0) + tempName = "NONAME"; + + unsigned long tmp_no_of_inputs = 0; + if (Convert2Block() != NULL) { + tmp_no_of_inputs = Convert2Block()->NoOfInputs; + } + unsigned long tmp_no_of_outputs = NoOfOutputs; + + text_buffer << "["; + + text_buffer << GetHtmlNodeLabel_DOTfile(tmp_no_of_inputs, tmp_no_of_outputs, GetName(), leading_space); + if (Convert2ClockTrigger() != NULL) { //temp_text = text_buffer + strlen(text_buffer) - 1; @@ -1359,7 +1368,7 @@ void DSP::Component::ComponentToDOTfile(std::ofstream &dot_plik, // draw macro input component_name = MacroInput_block->GetComponentName_DOTfile(); - dot_plik << " " << component_name << " " << GetMacroInputNodeParams_DOTfile() << ";" << std::endl; + dot_plik << " " << component_name << " " << GetMacroInputNodeParams_DOTfile() << ";" << std::endl; MacroInputEdgesToDOTfile(dot_plik, component_name, DrawnMacro); diff --git a/src/include/DSP_lib.h b/src/include/DSP_lib.h index 5bf1242..b858e21 100644 --- a/src/include/DSP_lib.h +++ b/src/include/DSP_lib.h @@ -11,7 +11,7 @@ #define DSP_VER_MAJOR 0 #define DSP_VER_MINOR 20 -#define DSP_VER_BUILD 11 // !!! without zeroes before, else this will be treated as octal number +#define DSP_VER_BUILD 12 // !!! without zeroes before, else this will be treated as octal number #define DSP_VER_YEAR 2023 #define DSP_VER DSP_VER_MAJOR.DSP_VER_MINOR.DSP_VER_BUILD diff --git a/src/include/DSP_modules.h b/src/include/DSP_modules.h index 8201444..2758779 100644 --- a/src/include/DSP_modules.h +++ b/src/include/DSP_modules.h @@ -1002,6 +1002,11 @@ class DSP::Component : public virtual DSP::name, public DSP::_connect_class /*! output_index - index of the rendered output */ virtual string GetComponentEdgeParams_DOTfile(const unsigned int &output_index = 0U); + + /*! generates component HMTL label and shape for DOT + */ + static string GetHtmlNodeLabel_DOTfile(const unsigned long &no_of_inputs, const unsigned long &no_of_outputs, const string &node_name, const string &leading_space); + //! Returns component node parameters used in DOTfile virtual string GetComponentNodeParams_DOTfile(const string &leading_space); //! Returns component node parameters used in DOTfile -- GitLab