Exemplo n.º 1
0
void HexColorEntry::setColor(const app::Color& color)
{
  m_entry.setTextf("%02x%02x%02x",
                   color.getRed(),
                   color.getGreen(),
                   color.getBlue());
}
Exemplo n.º 2
0
ViewProviderMeshNode::ViewProviderMeshNode() : pcOpenEdge(0), m_bEdit(false)
{
  ADD_PROPERTY(LineWidth,(2.0f));
  LineWidth.setConstraints(&floatRange);
  ADD_PROPERTY(PointSize,(2.0f));
  PointSize.setConstraints(&floatRange);
  ADD_PROPERTY(OpenEdges,(false));

  pOpenColor = new SoBaseColor();
  setOpenEdgeColorFrom(ShapeColor.getValue());
  pOpenColor->ref();

  pcLineStyle = new SoDrawStyle();
  pcLineStyle->ref();
  pcLineStyle->style = SoDrawStyle::LINES;
  pcLineStyle->lineWidth = LineWidth.getValue();

  pcPointStyle = new SoDrawStyle();
  pcPointStyle->ref();
  pcPointStyle->style = SoDrawStyle::POINTS;
  pcPointStyle->pointSize = PointSize.getValue();

  // read the correct shape color from the preferences
  Base::Reference<ParameterGrp> hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("Mod/Mesh");
  App::Color color = ShapeColor.getValue();
  unsigned long current = color.getPackedValue();
  unsigned long setting = hGrp->GetUnsigned("MeshColor", current);
  if ( current != setting )
  {
    color.setPackedValue((uint32_t)setting);
    ShapeColor.setValue(color);
  }
}
Exemplo n.º 3
0
// TODO this code is exactly the same as draw_alpha_slider() with a ui::Graphics
void draw_alpha_slider(she::Surface* s,
                       const gfx::Rect& rc,
                       const app::Color& color)
{
  const int xmax = MAX(1, rc.w-1);
  const doc::color_t c =
    (color.getType() != app::Color::MaskType ?
     doc::rgba(color.getRed(),
               color.getGreen(),
               color.getBlue(), 255): 0);

  for (int x=0; x<rc.w; ++x) {
    const int a = (255 * x / xmax);
    const doc::color_t c1 = doc::rgba_blender_normal(gridColor1, c, a);
    const doc::color_t c2 = doc::rgba_blender_normal(gridColor2, c, a);
    const int mid = rc.h/2;
    const int odd = (x / rc.h) & 1;
    s->drawVLine(
      app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c2: c1)),
      rc.x+x, rc.y, mid);
    s->drawVLine(
      app::color_utils::color_for_ui(app::Color::fromImage(IMAGE_RGB, odd ? c1: c2)),
      rc.x+x, rc.y+mid, rc.h-mid);
  }
}
Exemplo n.º 4
0
void RgbSliders::onSetColor(const app::Color& color)
{
  setAbsSliderValue(0, color.getRed());
  setAbsSliderValue(1, color.getGreen());
  setAbsSliderValue(2, color.getBlue());
  setAbsSliderValue(3, color.getAlpha());
}
ViewProviderDimension::ViewProviderDimension()
{
    sPixmap = "TechDraw_Dimension";

    static const char *group = "Dim Format";

    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
                                         .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels");
    std::string fontName = hGrp->GetASCII("LabelFont", "osifont");
    hGrp = App::GetApplication().GetUserParameter()
                                         .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
    double fontSize = hGrp->GetFloat("FontSize", 3.5);

    ADD_PROPERTY_TYPE(Font ,(fontName.c_str()),group,App::Prop_None, "The name of the font to use");
    ADD_PROPERTY_TYPE(Fontsize,(fontSize)    ,group,(App::PropertyType)(App::Prop_None),"Dimension text size in units");

    hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
    std::string lgName = hGrp->GetASCII("LineGroup","FC 0.70mm");
    auto lg = TechDraw::LineGroup::lineGroupFactory(lgName);
    double weight = lg->getWeight("Thin");
    delete lg;                                   //Coverity CID 174670
    ADD_PROPERTY_TYPE(LineWidth,(weight)    ,group,(App::PropertyType)(App::Prop_None),"Dimension line weight");

    hGrp = App::GetApplication().GetUserParameter()
                                        .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
    App::Color fcColor;
    fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x00000000));
    ADD_PROPERTY_TYPE(Color,(fcColor),group,App::Prop_None,"The color of the Dimension");

}
Exemplo n.º 6
0
void HsvSliders::onSetColor(const app::Color& color)
{
  setAbsSliderValue(0, color.getHue());
  setAbsSliderValue(1, color.getSaturation());
  setAbsSliderValue(2, color.getValue());
  setAbsSliderValue(3, color.getAlpha());
}
Exemplo n.º 7
0
static void draw_color(ui::Graphics* g, const Rect& rc, const app::Color& color)
{
  if (rc.w < 1 || rc.h < 1)
    return;

  app::Color::Type type = color.getType();

  if (type == app::Color::MaskType) {
    rectgrid(g, rc, gfx::Size(rc.w/4, rc.h/2));
    return;
  }
  else if (type == app::Color::IndexType) {
    int index = color.getIndex();

    if (index >= 0 && index < get_current_palette()->size()) {
      g->fillRect(color_utils::color_for_ui(color), rc);
    }
    else {
      g->fillRect(gfx::rgba(0, 0, 0), rc);
      g->drawLine(gfx::rgba(255, 255, 255),
        gfx::Point(rc.x+rc.w-2, rc.y+1),
        gfx::Point(rc.x+1, rc.y+rc.h-2));
    }
    return;
  }

  g->fillRect(color_utils::color_for_ui(color), rc);
}
Exemplo n.º 8
0
QColor QGCustomText::getSelectColor()
{
    Base::Reference<ParameterGrp> hGrp = getParmGroup();
    App::Color fcColor;
    fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x00FF0000));
    return fcColor.asValue<QColor>();
}
Exemplo n.º 9
0
QColor QGVPage::getBackgroundColor()
{
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
                                        .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
    App::Color fcColor;
    fcColor.setPackedValue(hGrp->GetUnsigned("Background", 0x70707000));
    return fcColor.asValue<QColor>();
}
Exemplo n.º 10
0
QColor QGIView::getSelectColor()
{
    Base::Reference<ParameterGrp> hGrp = getParmGroupCol();
    App::Color fcColor;
    fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x00FF0000));
    m_colSel = fcColor.asValue<QColor>();
    return m_colSel;
}
void PropertyColor::setPyObject(PyObject *value)
{
    App::Color cCol;
    if (PyTuple_Check(value) && PyTuple_Size(value) == 3) {
        PyObject* item;
        item = PyTuple_GetItem(value,0);
        if (PyFloat_Check(item))
            cCol.r = (float)PyFloat_AsDouble(item);
        else
            throw Base::Exception("Type in tuple must be float");
        item = PyTuple_GetItem(value,1);
        if (PyFloat_Check(item))
            cCol.g = (float)PyFloat_AsDouble(item);
        else
            throw Base::Exception("Type in tuple must be float");
        item = PyTuple_GetItem(value,2);
        if (PyFloat_Check(item))
            cCol.b = (float)PyFloat_AsDouble(item);
        else
            throw Base::Exception("Type in tuple must be float");
    }
    else if (PyTuple_Check(value) && PyTuple_Size(value) == 4) {
        PyObject* item;
        item = PyTuple_GetItem(value,0);
        if (PyFloat_Check(item))
            cCol.r = (float)PyFloat_AsDouble(item);
        else
            throw Base::Exception("Type in tuple must be float");
        item = PyTuple_GetItem(value,1);
        if (PyFloat_Check(item))
            cCol.g = (float)PyFloat_AsDouble(item);
        else
            throw Base::Exception("Type in tuple must be float");
        item = PyTuple_GetItem(value,2);
        if (PyFloat_Check(item))
            cCol.b = (float)PyFloat_AsDouble(item);
        else
            throw Base::Exception("Type in tuple must be float");
        item = PyTuple_GetItem(value,3);
        if (PyFloat_Check(item))
            cCol.a = (float)PyFloat_AsDouble(item);
        else
            throw Base::Exception("Type in tuple must be float");
    }
    else if (PyLong_Check(value)) {
        cCol.setPackedValue(PyLong_AsUnsignedLong(value));
    }
    else {
        std::string error = std::string("type must be int or tuple of float, not ");
        error += value->ob_type->tp_name;
        throw Py::TypeError(error);
    }

    setValue( cCol );
}
Exemplo n.º 12
0
void PaletteEntryEditor::setPaletteEntry(const app::Color& color)
{
    PalettePicks entries;
    getPicks(entries);

    color_t new_pal_color = doc::rgba(color.getRed(),
                                      color.getGreen(),
                                      color.getBlue(), 255);

    Palette* palette = get_current_palette();
    for (int c=0; c<palette->size(); c++) {
        if (entries[c])
            palette->setEntry(c, new_pal_color);
    }
}
Exemplo n.º 13
0
void ColorPopup::findBestfitIndex(const app::Color& color)
{
  if (!m_colorPalette)
    return;

  // Find bestfit palette entry
  int r = color.getRed();
  int g = color.getGreen();
  int b = color.getBlue();
  int a = color.getAlpha();

  // Search for the closest color to the RGB values
  int i = get_current_palette()->findBestfit(r, g, b, a, 0);
  if (i >= 0) {
    m_colorPalette->deselect();
    m_colorPalette->selectColor(i);
  }
}
Exemplo n.º 14
0
App::Color Cell::decodeColor(const std::string & color, const App::Color & defaultColor)
{
    if (color.size() == 7 || color.size() == 9) {
        App::Color c;

        if (color[0] != '#')
            return defaultColor;
        unsigned int value = strtoul(color.c_str() + 1, 0, 16);

        if (color.size() == 7)
            value = (value << 8) | 0xff;

        c.setPackedValue(value);
        return c;
    }
    else
        return defaultColor;
}
Exemplo n.º 15
0
QColor QGCustomText::getNormalColor()
{
    QColor result;
    QGIView *parent;
    QGraphicsItem* qparent = parentItem();
    if (qparent == nullptr) {
        parent = nullptr;
    } else {
        parent = dynamic_cast<QGIView *> (qparent);
    }

    if (parent != nullptr) {
        result = parent->getNormalColor();
    } else {
        Base::Reference<ParameterGrp> hGrp = getParmGroup();
        App::Color fcColor;
        fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000));
        result = fcColor.asValue<QColor>();
    }
    return result;
}
Exemplo n.º 16
0
raster::color_t color_utils::color_for_layer(const app::Color& color, Layer* layer)
{
  raster::color_t pixel_color;

  if (color.getType() == app::Color::MaskType) {
    pixel_color = layer->getSprite()->getTransparentColor();
  }
  else {
    PixelFormat format = layer->getSprite()->getPixelFormat();
    pixel_color = color_for_image(color, format);
  }

  return fixup_color_for_layer(layer, pixel_color);
}
Exemplo n.º 17
0
raster::color_t color_utils::color_for_image(const app::Color& color, PixelFormat format)
{
  if (color.getType() == app::Color::MaskType)
    return 0;

  raster::color_t c = -1;

  switch (format) {
    case IMAGE_RGB:
      c = rgba(color.getRed(), color.getGreen(), color.getBlue(), 255);
      break;
    case IMAGE_GRAYSCALE:
      c = graya(color.getGray(), 255);
      break;
    case IMAGE_INDEXED:
      if (color.getType() == app::Color::IndexType)
        c = color.getIndex();
      else
        c = get_current_palette()->findBestfit(color.getRed(), color.getGreen(), color.getBlue());
      break;
  }

  return c;
}
Exemplo n.º 18
0
void ColorPopup::setColor(const app::Color& color,
                          const SetColorOptions options)
{
  m_color = color;

  if (m_simpleColors) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();
    int a = color.getAlpha();
    int i = g_simplePal->findExactMatch(r, g, b, a, -1);
    if (i >= 0)
      m_simpleColors->selectColor(i);
    else
      m_simpleColors->deselect();
  }

  if (color.getType() == app::Color::IndexType) {
    if (m_colorPalette) {
      m_colorPalette->deselect();
      m_colorPalette->selectColor(color.getIndex());
    }
  }

  m_sliders.setColor(m_color);
  if (!m_disableHexUpdate)
    m_hexColorEntry.setColor(m_color);

  if (options == ChangeType)
    selectColorType(m_color.getType());

  // Set the new color
  Shade shade = m_oldAndNew.getShade();
  shade.resize(2);
  shade[1] = (color.getType() == app::Color::IndexType ? color.toRgb(): color);
  if (!m_insideChange)
    shade[0] = shade[1];
  m_oldAndNew.setShade(shade);
}
Exemplo n.º 19
0
ui::Color color_utils::color_for_ui(const app::Color& color)
{
  ui::Color c = ui::ColorNone;

  switch (color.getType()) {

    case app::Color::MaskType:
      c = ui::ColorNone;
      break;

    case app::Color::RgbType:
    case app::Color::HsvType:
      c = ui::rgba(color.getRed(),
                   color.getGreen(),
                   color.getBlue(), 255);
      break;

    case app::Color::GrayType:
      c = ui::rgba(color.getGray(),
                   color.getGray(),
                   color.getGray(), 255);
      break;

    case app::Color::IndexType: {
      int i = color.getIndex();
      ASSERT(i >= 0 && i < (int)get_current_palette()->size());

      uint32_t _c = get_current_palette()->getEntry(i);
      c = ui::rgba(rgba_getr(_c),
                   rgba_getg(_c),
                   rgba_getb(_c), 255);
      break;
    }

  }

  return c;
}
Exemplo n.º 20
0
int color_utils::color_for_allegro(const app::Color& color, int depth)
{
  int c = -1;

  switch (color.getType()) {

    case app::Color::MaskType:
      c = get_mask_for_bitmap(depth);
      break;

    case app::Color::RgbType:
    case app::Color::HsvType:
      c = makeacol_depth(depth,
                         color.getRed(),
                         color.getGreen(),
                         color.getBlue(), 255);
      break;

    case app::Color::GrayType:
      c = color.getGray();
      if (depth != 8)
        c = makeacol_depth(depth, c, c, c, 255);
      break;

    case app::Color::IndexType:
      c = color.getIndex();
      if (depth != 8) {
        ASSERT(c >= 0 && c < (int)get_current_palette()->size());

        uint32_t _c = get_current_palette()->getEntry(c);
        c = makeacol_depth(depth,
                           rgba_getr(_c),
                           rgba_getg(_c),
                           rgba_getb(_c), 255);
      }
      break;

  }

  return c;
}
Exemplo n.º 21
0
std::string DrawViewSpreadsheet::getSheetImage(void)
{
    std::stringstream result;

    App::DocumentObject* link = Source.getValue();
    std::string scellstart = CellStart.getValue();
    std::string scellend = CellEnd.getValue();

    std::vector<std::string> availcolumns = getAvailColumns();

    // build rows range and columns range
    std::vector<std::string> columns;
    std::vector<int> rows;
    try {
        for (unsigned int i=0; i<scellstart.length(); ++i) {
            if (isdigit(scellstart[i])) {
                columns.push_back(scellstart.substr(0,i));
                rows.push_back(std::atoi(scellstart.substr(i,scellstart.length()-1).c_str()));
            }
        }
        for (unsigned int i=0; i<scellend.length(); ++i) {
            if (isdigit(scellend[i])) {
                std::string startcol = columns.back();
                std::string endcol = scellend.substr(0,i);
                bool valid = false;
                for (std::vector<std::string>::const_iterator j = availcolumns.begin(); j != availcolumns.end(); ++j) {
                    if ( (*j) == startcol) {
                        if ( (*j) != endcol) {
                            valid = true;
                        }
                    } else {
                        if (valid) {
                            if ( (*j) == endcol) {
                                columns.push_back((*j));
                                valid = false;
                            } else {
                                columns.push_back((*j));
                            }
                        }
                    }
                }
                int endrow = std::atoi(scellend.substr(i,scellend.length()-1).c_str());
                for (int j=rows.back()+1; j<=endrow; ++j) {
                    rows.push_back(j);
                }
            }
        }
    } catch (std::exception) {
        Base::Console().Error("Invalid cell range for %s\n",getNameInDocument());
        return result.str();
    }

    // create the containing group
    std::string ViewName = Label.getValue();

    result << getSVGHead();

    App::Color c = TextColor.getValue();
    result  << "<g id=\"" << ViewName << "\">" << endl;

    // fill the cells
    float rowoffset = 0.0;
    float coloffset = 0.0;
    float cellheight = 100;
    float cellwidth = 100;
    std::string celltext;
    Spreadsheet::Sheet* sheet = static_cast<Spreadsheet::Sheet*>(link);
    std::vector<std::string> skiplist;
    for (std::vector<std::string>::const_iterator col = columns.begin(); col != columns.end(); ++col) {
        // create a group for each column
        result << "  <g id=\"" << ViewName << "_col" << (*col) << "\">" << endl;
        for (std::vector<int>::const_iterator row = rows.begin(); row != rows.end(); ++row) {
            // get cell size
            std::stringstream srow;
            srow << (*row);
            App::CellAddress address((*col) + srow.str());
            cellwidth = sheet->getColumnWidth(address.col());
            cellheight = sheet->getRowHeight(address.row());
            celltext = "";
            // get the text
            App::Property* prop = sheet->getPropertyByName(address.toString().c_str());
            std::stringstream field;
            if (prop != 0) {
                if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId())))
                    field << static_cast<App::PropertyQuantity*>(prop)->getValue();
                else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId())))
                    field << static_cast<App::PropertyFloat*>(prop)->getValue();
                else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId())))
                    field << static_cast<App::PropertyString*>(prop)->getValue();
                else
                    assert(0);
                celltext = field.str();
            }
            // get colors, style, alignment and span
            int alignment;
            std::string bcolor = "none";
            std::string fcolor = c.asCSSString();
            std::string textstyle = "";
            Spreadsheet::Cell* cell = sheet->getCell(address);
            if (cell) {
                App::Color f,b;
                std::set<std::string> st;
                int colspan, rowspan;
                if (cell->getBackground(b)) {
                    bcolor = b.asCSSString();
                }
                if (cell->getForeground(f)) {
                    fcolor = f.asCSSString();
                }
                if (cell->getStyle(st)) {
                    for (std::set<std::string>::const_iterator i = st.begin(); i != st.end(); ++i) {
                         if ((*i) == "bold")
                            textstyle = textstyle + "font-weight: bold; ";
                        else if ((*i) == "italic")
                            textstyle = textstyle + "font-style: italic; ";
                        else if ((*i) == "underline")
                            textstyle = textstyle + "text-decoration: underline; ";
                    }
                }
                if (cell->getSpans(rowspan,colspan)) {
                    for (int i=0; i<colspan; ++i) {
                        for (int j=0; j<rowspan; ++j) {
                            App::CellAddress nextcell(address.row()+j,address.col()+i);
                            if (i > 0)
                                cellwidth = cellwidth + sheet->getColumnWidth(nextcell.col());
                            if (j > 0)
                                cellheight = cellheight + sheet->getRowHeight(nextcell.row());
                            if ( (i > 0) || (j > 0) )
                                skiplist.push_back(nextcell.toString());
                        }
                    }
                }
                cell->getAlignment(alignment);
            }
            // skip cell if found in skiplist
            if (std::find(skiplist.begin(), skiplist.end(), address.toString()) == skiplist.end()) {
                result << "    <rect x=\"" << coloffset << "\" y=\"" << rowoffset << "\" width=\"" << cellwidth
                       << "\" height=\"" << cellheight << "\" style=\"fill:" << bcolor << ";stroke-width:"
                       << LineWidth.getValue()/Scale.getValue() << ";stroke:" << c.asCSSString() << ";\" />" << endl;
                if (alignment & Spreadsheet::Cell::ALIGNMENT_LEFT)
                    result << "    <text style=\"" << textstyle << "\" x=\"" << coloffset + TextSize.getValue()/2 << "\" y=\"" << rowoffset + 0.75 * cellheight << "\" font-family=\"" ;
                if (alignment & Spreadsheet::Cell::ALIGNMENT_HCENTER)
                    result << "    <text text-anchor=\"middle\" style=\"" << textstyle << "\" x=\"" << coloffset + cellwidth/2 << "\" y=\"" << rowoffset + 0.75 * cellheight << "\" font-family=\"" ;
                if (alignment & Spreadsheet::Cell::ALIGNMENT_RIGHT)
                    result << "    <text text-anchor=\"end\" style=\"" << textstyle << "\" x=\"" << coloffset + (cellwidth - TextSize.getValue()/2) << "\" y=\"" << rowoffset + 0.75 * cellheight << "\" font-family=\"" ;
                result << Font.getValue() << "\"" << " font-size=\"" << TextSize.getValue() << "\""
                       << " fill=\"" << fcolor << "\">" << celltext << "</text>" << endl;
            }
            rowoffset = rowoffset + cellheight;
        }
        result << "  </g>" << endl;
        rowoffset = 0.0;
        coloffset = coloffset + cellwidth;
    }

    // close the containing group
    result << "</g>" << endl;

    result << getSVGTail();

    return result.str();
}
Exemplo n.º 22
0
void ColorBar::onColorButtonChange(const app::Color& color)
{
    if (color.getType() == app::Color::IndexType)
        m_paletteView.selectColor(color.getIndex());
}
Exemplo n.º 23
0
void set_config_color(const char* section, const char* name, const app::Color& value)
{
  set_config_string(section, name, value.toString().c_str());
}
Exemplo n.º 24
0
void EyedropperCommand::pickSample(const doc::Site& site,
                                   const gfx::Point& pixelPos,
                                   app::Color& color)
{
  // Check if we've to grab alpha channel or the merged color.
  Preferences& pref = Preferences::instance();
  bool allLayers =
    (pref.eyedropper.sample() == app::gen::EyedropperSample::ALL_LAYERS);

  ColorPicker picker;
  picker.pickColor(site,
                   pixelPos,
                   (allLayers ?
                    ColorPicker::FromComposition:
                    ColorPicker::FromActiveLayer));

  app::gen::EyedropperChannel channel =
    pref.eyedropper.channel();

  app::Color picked = picker.color();

  switch (channel) {
    case app::gen::EyedropperChannel::COLOR_ALPHA:
      color = picked;
      break;
    case app::gen::EyedropperChannel::COLOR:
      if (picked.getAlpha() > 0)
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::ALPHA:
      switch (color.getType()) {

        case app::Color::RgbType:
        case app::Color::IndexType:
          color = app::Color::fromRgb(color.getRed(),
                                      color.getGreen(),
                                      color.getBlue(),
                                      picked.getAlpha());
          break;

        case app::Color::HsvType:
          color = app::Color::fromHsv(color.getHue(),
                                      color.getSaturation(),
                                      color.getValue(),
                                      picked.getAlpha());
          break;

        case app::Color::GrayType:
          color = app::Color::fromGray(color.getGray(),
                                       picked.getAlpha());
          break;

      }
      break;
    case app::gen::EyedropperChannel::RGBA:
      if (picked.getType() == app::Color::RgbType)
        color = picked;
      else
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::RGB:
      if (picked.getAlpha() > 0)
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::HSVA:
      if (picked.getType() == app::Color::HsvType)
        color = picked;
      else
        color = app::Color::fromHsv(picked.getHue(),
                                    picked.getSaturation(),
                                    picked.getValue(),
                                    picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::HSV:
      if (picked.getAlpha() > 0)
        color = app::Color::fromHsv(picked.getHue(),
                                    picked.getSaturation(),
                                    picked.getValue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::GRAYA:
      if (picked.getType() == app::Color::GrayType)
        color = picked;
      else
        color = app::Color::fromGray(picked.getGray(),
                                     picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::GRAY:
      if (picked.getAlpha() > 0)
        color = app::Color::fromGray(picked.getGray(),
                                     color.getAlpha());
      break;
    case app::gen::EyedropperChannel::INDEX:
      color = app::Color::fromIndex(picked.getIndex());
      break;
  }
}
Exemplo n.º 25
0
void ColorSliders::onSetColor(const app::Color& color)
{
  setAbsSliderValue(Channel::Red,           color.getRed());
  setAbsSliderValue(Channel::Green,         color.getGreen());
  setAbsSliderValue(Channel::Blue,          color.getBlue());
  setAbsSliderValue(Channel::HsvHue,        int(color.getHsvHue()));
  setAbsSliderValue(Channel::HsvSaturation, int(color.getHsvSaturation() * 100.0));
  setAbsSliderValue(Channel::HsvValue,      int(color.getHsvValue() * 100.0));
  setAbsSliderValue(Channel::HslHue,        int(color.getHslHue()));
  setAbsSliderValue(Channel::HslSaturation, int(color.getHslSaturation() * 100.0));
  setAbsSliderValue(Channel::HslLightness,  int(color.getHslLightness() * 100.0));
  setAbsSliderValue(Channel::Gray,          color.getGray());
  setAbsSliderValue(Channel::Alpha,         color.getAlpha());
}
Exemplo n.º 26
0
void QGIViewPart::drawViewPart()
{
    if ( getViewObject() == 0 ||
         !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
        return;
    }

    TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(getViewObject());

    float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor;
    float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor;

    prepareGeometryChange();

#if MOD_TECHDRAW_HANDLE_FACES
    // Draw Faces
    std::vector<TechDraw::DrawHatch*> hatchObjs = viewPart->getHatches();
    const std::vector<TechDrawGeometry::Face *> &faceGeoms = viewPart->getFaceGeometry();
    std::vector<TechDrawGeometry::Face *>::const_iterator fit = faceGeoms.begin();
    for(int i = 0 ; fit != faceGeoms.end(); fit++, i++) {
        QGIFace* newFace = drawFace(*fit,i);
        TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs);
        if (fHatch) {
            if (!fHatch->HatchPattern.isEmpty()) {
                App::Color hColor = fHatch->HatchColor.getValue();
                newFace->setHatchColor(hColor.asCSSString());
                newFace->setHatch(fHatch->HatchPattern.getValue());
            }
        }
        newFace->setZValue(ZVALUE::FACE);
        newFace->setPrettyNormal();
    }
#endif //#if MOD_TECHDRAW_HANDLE_FACES

    // Draw Edges
    const std::vector<TechDrawGeometry::BaseGeom *> &geoms = viewPart->getEdgeGeometry();
    std::vector<TechDrawGeometry::BaseGeom *>::const_iterator itEdge = geoms.begin();
    QGIEdge* item;
    for(int i = 0 ; itEdge != geoms.end(); itEdge++, i++) {
        bool showEdge = false;
        if ((*itEdge)->visible) {
            if (((*itEdge)->classOfEdge == ecHARD) ||
                ((*itEdge)->classOfEdge == ecOUTLINE) ||
                (((*itEdge)->classOfEdge == ecSMOOTH) && viewPart->ShowSmoothLines.getValue()) ||
                (((*itEdge)->classOfEdge == ecSEAM) && viewPart->ShowSeamLines.getValue())) {
                showEdge = true;
            }
        } else {
            if (viewPart->ShowHiddenLines.getValue()) {
                showEdge = true;
            }
        }
        if (showEdge) {
            item = new QGIEdge(i);
            addToGroup(item);                                                   //item is at scene(0,0), not group(0,0)
            item->setPos(0.0,0.0);
            item->setPath(drawPainterPath(*itEdge));
            item->setStrokeWidth(lineWidth);
            item->setZValue(ZVALUE::EDGE);
            if(!(*itEdge)->visible) {
                item->setStrokeWidth(lineWidthHid);
                item->setHiddenEdge(true);
                item->setZValue(ZVALUE::HIDEDGE);
            }
            item->setPrettyNormal();
            //debug a path
            //QPainterPath edgePath=drawPainterPath(*itEdge);
            //std::stringstream edgeId;
            //edgeId << "QGIVP.edgePath" << i;
            //dumpPath(edgeId.str().c_str(),edgePath);
         }
    }

    // Draw Vertexs:
    const std::vector<TechDrawGeometry::Vertex *> &verts = viewPart->getVertexGeometry();
    std::vector<TechDrawGeometry::Vertex *>::const_iterator vert = verts.begin();
    for(int i = 0 ; vert != verts.end(); ++vert, i++) {
        QGIVertex *item = new QGIVertex(i);
        addToGroup(item);
        item->setPos((*vert)->pnt.fX, (*vert)->pnt.fY);                //this is in ViewPart coords
        item->setRadius(lineWidth * vertexScaleFactor);
        item->setZValue(ZVALUE::VERTEX);
     }
}
Exemplo n.º 27
0
void GraySlider::onSetColor(const app::Color& color)
{
  setSliderValue(0, color.getGray());
}
Exemplo n.º 28
0
void GraySlider::onSetColor(const app::Color& color)
{
  setAbsSliderValue(0, color.getGray());
  setAbsSliderValue(1, color.getAlpha());
}
Exemplo n.º 29
0
void QGIViewPart::drawViewPart()
{
    auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
    if ( viewPart == nullptr ) {
        return;
    }

    float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor;
    float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor;
    float lineWidthIso = viewPart->IsoWidth.getValue() * lineScaleFactor;

    prepareGeometryChange();
    removePrimitives();                      //clean the slate
    removeDecorations();

#if MOD_TECHDRAW_HANDLE_FACES
    if (viewPart->handleFaces()) {
        // Draw Faces
        std::vector<TechDraw::DrawHatch*> hatchObjs = viewPart->getHatches();
        const std::vector<TechDrawGeometry::Face *> &faceGeoms = viewPart->getFaceGeometry();
        std::vector<TechDrawGeometry::Face *>::const_iterator fit = faceGeoms.begin();
        for(int i = 0 ; fit != faceGeoms.end(); fit++, i++) {
            QGIFace* newFace = drawFace(*fit,i);
            TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs);
            if (fHatch) {
                if (!fHatch->HatchPattern.isEmpty()) {
                    App::Color hColor = fHatch->HatchColor.getValue();
                    newFace->setHatchColor(hColor.asCSSString());
                    newFace->setHatch(fHatch->HatchPattern.getValue());
                }
            }
            newFace->setDrawEdges(false);
            newFace->setZValue(ZVALUE::FACE);
            newFace->setPrettyNormal();
        }
    }
#endif //#if MOD_TECHDRAW_HANDLE_FACES

    // Draw Edges
    const std::vector<TechDrawGeometry::BaseGeom *> &geoms = viewPart->getEdgeGeometry();
    std::vector<TechDrawGeometry::BaseGeom *>::const_iterator itEdge = geoms.begin();
    QGIEdge* item;
    for(int i = 0 ; itEdge != geoms.end(); itEdge++, i++) {
        bool showEdge = false;
        if ((*itEdge)->visible) {
            if (((*itEdge)->classOfEdge == ecHARD) ||
                ((*itEdge)->classOfEdge == ecOUTLINE) ||
                (((*itEdge)->classOfEdge == ecSMOOTH) && viewPart->SmoothVisible.getValue()) ||
                (((*itEdge)->classOfEdge == ecSEAM) && viewPart->SeamVisible.getValue())    ||
                (((*itEdge)->classOfEdge == ecUVISO) && viewPart->IsoVisible.getValue())) {
                showEdge = true;
            }
        } else {
            if ( (((*itEdge)->classOfEdge == ecHARD) && (viewPart->HardHidden.getValue())) ||
                 (((*itEdge)->classOfEdge == ecOUTLINE) && (viewPart->HardHidden.getValue())) ||
                 (((*itEdge)->classOfEdge == ecSMOOTH) && (viewPart->SmoothHidden.getValue())) ||
                 (((*itEdge)->classOfEdge == ecSEAM) && (viewPart->SeamHidden.getValue()))    ||
                 (((*itEdge)->classOfEdge == ecUVISO) && (viewPart->IsoHidden.getValue())) ) {
                showEdge = true;
            }
        }
        if (showEdge) {
            item = new QGIEdge(i);
            addToGroup(item);                                                   //item is at scene(0,0), not group(0,0)
            item->setPos(0.0,0.0);                                              //now at group(0,0)
            item->setPath(drawPainterPath(*itEdge));
            item->setWidth(lineWidth);
            item->setZValue(ZVALUE::EDGE);
            if(!(*itEdge)->visible) {
                item->setWidth(lineWidthHid);
                item->setHiddenEdge(true);
                item->setZValue(ZVALUE::HIDEDGE);
            }
            if ((*itEdge)->classOfEdge == ecUVISO) {
                item->setWidth(lineWidthIso);
            }
            item->setPrettyNormal();
            //debug a path
            //QPainterPath edgePath=drawPainterPath(*itEdge);
            //std::stringstream edgeId;
            //edgeId << "QGIVP.edgePath" << i;
            //dumpPath(edgeId.str().c_str(),edgePath);
         }
    }

    // Draw Vertexs:
    const std::vector<TechDrawGeometry::Vertex *> &verts = viewPart->getVertexGeometry();
    std::vector<TechDrawGeometry::Vertex *>::const_iterator vert = verts.begin();
    bool showCenters = viewPart->ArcCenterMarks.getValue();
    double cAdjust = viewPart->CenterScale.getValue();
    for(int i = 0 ; vert != verts.end(); ++vert, i++) {
        if ((*vert)->isCenter) {
            if (showCenters) {
                QGICMark* cmItem = new QGICMark(i);
                addToGroup(cmItem);
                cmItem->setPos((*vert)->pnt.fX, (*vert)->pnt.fY);                //this is in ViewPart coords
                cmItem->setThick(0.5 * lineWidth * lineScaleFactor);             //need minimum?
                cmItem->setSize( cAdjust * lineWidth * vertexScaleFactor);
                cmItem->setZValue(ZVALUE::VERTEX);
            }
        } else {
            QGIVertex *item = new QGIVertex(i);
            addToGroup(item);
            item->setPos((*vert)->pnt.fX, (*vert)->pnt.fY);                //this is in ViewPart coords
            item->setRadius(lineWidth * vertexScaleFactor);
            item->setZValue(ZVALUE::VERTEX);
        }
    }
    //draw section line
    if (viewPart->ShowSectionLine.getValue()) {
        auto refs = viewPart->getSectionRefs();
        for (auto& r:refs) {
            drawSectionLine(r, true);
        }
    }
    //draw center lines
    drawCenterLines(true);
}
Exemplo n.º 30
0
app::Color get_config_color(const char* section, const char* name, const app::Color& value)
{
  return app::Color::fromString(get_config_string(section, name, value.toString().c_str()));
}