Bugfix: net color was not properly set in net tracer

This commit is contained in:
Matthias Koefferlein 2022-06-18 16:58:55 +02:00
parent f6c0959b6b
commit 555d32f280
6 changed files with 100 additions and 15 deletions

View File

@ -339,13 +339,13 @@ NetTracerSymbolInfo::parse (tl::Extractor &ex)
// Net implementation
NetTracerNet::NetTracerNet ()
: m_dbu (0.001), m_incomplete (true), m_color (0), m_trace_path (false)
: m_dbu (0.001), m_incomplete (true), m_color (), m_trace_path (false)
{
// .. nothing yet ..
}
NetTracerNet::NetTracerNet (const NetTracer &tracer, const db::ICplxTrans &trans, const db::Layout &layout, db::cell_index_type cell_index, const std::string &layout_filename, const std::string &layout_name, const NetTracerData &data)
: m_name (tracer.name ()), m_incomplete (tracer.incomplete ()), m_color (0), m_trace_path (false)
: m_name (tracer.name ()), m_incomplete (tracer.incomplete ()), m_color (), m_trace_path (false)
{
m_dbu = layout.dbu ();
m_top_cell_name = layout.cell_name (cell_index);

View File

@ -27,10 +27,7 @@
#include "dbNetTracer.h"
#include "dbLayerProperties.h"
#include "dbTechnology.h"
#if defined(HAVE_QT)
# include <QColor>
#endif
#include "tlColor.h"
namespace db
{
@ -199,7 +196,7 @@ public:
/**
* @brief Gets the color in which the net is drawn
*/
uint32_t color () const
const tl::Color &color () const
{
return m_color;
}
@ -207,7 +204,7 @@ public:
/**
* @brief Sets the color in which the net is drawn
*/
void set_color (uint32_t c)
void set_color (const tl::Color &c)
{
m_color = c;
}
@ -353,7 +350,7 @@ private:
db::Shapes m_shapes;
std::map <unsigned int, std::pair <db::LayerProperties, db::LayerProperties> > m_layers;
std::map <unsigned int, std::string> m_cell_names;
uint32_t m_color;
tl::Color m_color;
db::DBox m_start_search_box, m_stop_search_box;
bool m_trace_path;

View File

@ -586,16 +586,17 @@ NetTracerDialog::menu_activated (const std::string &symbol)
}
void
NetTracerDialog::net_color_changed (QColor color)
NetTracerDialog::net_color_changed (QColor qc)
{
bool changed = false;
tl::Color color (qc);
QList<QListWidgetItem *> selected_items = net_list->selectedItems ();
for (QList<QListWidgetItem *>::const_iterator item = selected_items.begin (); item != selected_items.end (); ++item) {
int item_index = net_list->row (*item);
if (item_index >= 0 && item_index < int (mp_nets.size ())) {
if (color != mp_nets [item_index]->color ()) {
mp_nets [item_index]->set_color (color.rgb ());
mp_nets [item_index]->set_color (color);
changed = true;
}
}
@ -1052,15 +1053,17 @@ NetTracerDialog::update_info ()
// determine and set the common net color
if (selected_items.size () != 1) {
net_color->set_color (QColor ());
net_color->setEnabled (false);
} else {
QColor nc;
int item_index = net_list->row (*selected_items.begin ());
if (item_index >= 0 && item_index < int (mp_nets.size ())) {
nc = mp_nets [item_index]->color ();
nc = mp_nets [item_index]->color ().to_qc ();
}
net_color->set_color (nc);
@ -1093,12 +1096,12 @@ NetTracerDialog::update_list ()
item->setData (Qt::DisplayRole, tl::to_qstring (mp_nets [i]->name ()));
if (tl::Color (mp_nets [i]->color ()).is_valid ()) {
if (mp_nets [i]->color ().is_valid ()) {
QPixmap pxmp (icon_size);
QPainter pxpainter (&pxmp);
pxpainter.setPen (QPen (text_color));
pxpainter.setBrush (QBrush (mp_nets [i]->color ()));
pxpainter.setBrush (QBrush (mp_nets [i]->color ().to_qc ()));
QRect r (0, 0, pxmp.width () - 1, pxmp.height () - 1);
pxpainter.drawRect (r);

View File

@ -43,6 +43,16 @@ Color::Color (color_t color)
// .. nothing yet ..
}
#if defined(HAVE_QT)
Color::Color (const QColor &qc)
: m_color (0)
{
if (qc.isValid ()) {
m_color = qc.rgba ();
}
}
#endif
Color::Color (unsigned int r, unsigned int g, unsigned int b, unsigned int alpha)
: m_color ((b & 0xff) | ((g & 0xff) << 8) | ((r & 0xff) << 16) | ((alpha & 0xff) << 24))
{
@ -52,8 +62,19 @@ Color::Color (unsigned int r, unsigned int g, unsigned int b, unsigned int alpha
Color::Color (const std::string &name)
{
m_color = 0;
init_from_string (name.c_str ());
}
tl::Extractor ex (name.c_str ());
Color::Color (const char *name)
{
m_color = 0;
init_from_string (name);
}
void
Color::init_from_string (const char *s)
{
tl::Extractor ex (s);
unsigned int n = 0;
@ -112,6 +133,14 @@ Color::to_string () const
}
}
#if defined(HAVE_QT)
QColor
Color::to_qc () const
{
return is_valid () ? QColor (rgb ()) : QColor ();
}
#endif
bool
Color::is_valid () const
{

View File

@ -28,6 +28,10 @@
#include <stdint.h>
#include <string>
#if defined(HAVE_QT)
# include <QColor>
#endif
namespace tl
{
@ -60,9 +64,18 @@ public:
/**
* @brief Creates a color from a RGB triplet
*
* Note: this will set the alpha value to 255.
*/
Color (color_t color);
#if defined(HAVE_QT)
/**
* @brief Creates a color from a QColor
*/
Color (const QColor &qc);
#endif
/**
* @brief Creates a color from a RGB triplet and alpha value
*
@ -75,6 +88,11 @@ public:
*/
Color (const std::string &name);
/**
* @brief Creates a color value from a string
*/
Color (const char *name);
/**
* @brief Comparison: equal
*/
@ -104,6 +122,13 @@ public:
*/
std::string to_string () const;
#if defined(HAVE_QT)
/**
* @brief Gets the QColor from the color
*/
QColor to_qc () const;
#endif
/**
* @brief Gets a value indicating whether the color is valid
*/
@ -172,8 +197,30 @@ public:
private:
color_t m_color;
void init_from_string (const char *s);
};
#if defined(HAVE_QT)
/**
* @brief Provides conversion of a color_t to QColor
*/
inline QColor c2qc (color_t c)
{
return Color (c).to_qc ();
}
/**
* @brief Provides conversion of a QColor to color_t
*/
inline color_t qc2c (const QColor &qc)
{
return Color (qc).rgb ();
}
#endif
}
#endif

View File

@ -35,6 +35,10 @@ TEST(1)
EXPECT_EQ (tl::Color ().rgb (), 0x00000000);
#if defined(HAVE_QT)
EXPECT_EQ (tl::Color (QColor ()).is_valid (), false);
EXPECT_EQ (tl::Color (QColor ()).to_string (), "");
EXPECT_EQ (tl::Color (QColor ()).rgb (), 0x00000000);
EXPECT_EQ (tl::Color (QColor ()).to_qc ().isValid (), false);
EXPECT_EQ (QColor ().isValid (), false);
EXPECT_EQ (tl::to_string (QColor ().name ()), "#000000"); // why?
EXPECT_EQ (QColor ().rgb (), 0xff000000);
@ -48,6 +52,11 @@ TEST(2)
EXPECT_EQ (tl::Color (0x102030).rgb (), 0xff102030);
#if defined(HAVE_QT)
EXPECT_EQ (tl::Color (QColor (0x102030)).is_valid (), true);
EXPECT_EQ (tl::Color (QColor (0x102030)).to_string (), "#102030");
EXPECT_EQ (tl::Color (QColor (0x102030)).rgb (), 0xff102030);
EXPECT_EQ (tl::Color (QColor (0x102030)).to_qc ().isValid (), true);
EXPECT_EQ (tl::to_string (tl::Color (QColor (0x102030)).to_qc ().name ()), "#102030");
EXPECT_EQ (QColor (0x102030).isValid (), true);
EXPECT_EQ (tl::to_string (QColor (0x102030).name ()), "#102030");
EXPECT_EQ (QColor (0x102030).rgb (), 0xff102030);