diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 06c5fcb34..7c8e60665 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -841,6 +841,7 @@ SOURCE_GROUP("View3D\\Viewprovider" FILES ${Viewprovider_SRCS}) SET(Inventor_CPP_SRCS Inventor/SoDrawingGrid.cpp Inventor/SoAutoZoomTranslation.cpp + Inventor/MarkerBitmaps.cpp SoFCBackgroundGradient.cpp SoFCBoundingBox.cpp SoFCColorBar.cpp @@ -863,6 +864,7 @@ SET(Inventor_SRCS ${Inventor_CPP_SRCS} Inventor/SoDrawingGrid.h Inventor/SoAutoZoomTranslation.h + Inventor/MarkerBitmaps.h SoFCBackgroundGradient.h SoFCBoundingBox.h SoFCColorBar.h diff --git a/src/Gui/Inventor/MarkerBitmaps.cpp b/src/Gui/Inventor/MarkerBitmaps.cpp new file mode 100644 index 000000000..8ddef34af --- /dev/null +++ b/src/Gui/Inventor/MarkerBitmaps.cpp @@ -0,0 +1,176 @@ +/*************************************************************************** + * Copyright (c) 2016 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include "MarkerBitmaps.h" + +using namespace Gui::Inventor; + +/* +from PySide import QtCore +from PySide import QtGui + +def makeIcon(s): + p=QtGui.QPixmap(s,s) + painter=QtGui.QPainter(p) + painter.setBrush(QtCore.Qt.SolidPattern) + painter.drawEllipse(1,1,s-2,s-2) + painter.end() + + buffer=QtCore.QBuffer() + buffer.open(buffer.WriteOnly) + p.save(buffer,"XPM") + buffer.close() + + ary=buffer.buffer() + lines=ary.split(",") + ba=QtCore.QByteArray() + for i in lines[3:]: + ba = ba.append(i) + + ba=ba.replace("#","x") + ba=ba.replace("."," ") + print (ba.data()) +*/ + +//CIRCLE_FILLED_11_11 +const int CIRCLE11_WIDTH = 11; +const int CIRCLE11_HEIGHT = 11; +const char circle11_marker[CIRCLE11_WIDTH * CIRCLE11_HEIGHT + 1] = { +" " +" xxxxxx " +" xxxxxxxx " +" xxxxxxxx " +" xxxxxxxxxx" +" xxxxxxxxxx" +" xxxxxxxxxx" +" xxxxxxxxxx" +" xxxxxxxx " +" xxxxxxxx " +" xxxxxx "}; + + +//CIRCLE_FILLED_13_13 +const int CIRCLE13_WIDTH = 13; +const int CIRCLE13_HEIGHT = 13; +const char circle13_marker[CIRCLE13_WIDTH * CIRCLE13_HEIGHT + 1] = { +" " +" xxxxxx " +" xxxxxxxx " +" xxxxxxxxxx " +" xxxxxxxxxxxx" +" xxxxxxxxxxxx" +" xxxxxxxxxxxx" +" xxxxxxxxxxxx" +" xxxxxxxxxxxx" +" xxxxxxxxxxxx" +" xxxxxxxxxx " +" xxxxxxxx " +" xxxxxx "}; + + +//CIRCLE_FILLED_15_15 +const int CIRCLE15_WIDTH = 15; +const int CIRCLE15_HEIGHT = 15; +const char circle15_marker[CIRCLE15_WIDTH * CIRCLE15_HEIGHT + 1] = { +" " +" xxxxxx " +" xxxxxxxxxx " +" xxxxxxxxxxxx " +" xxxxxxxxxxxx " +" xxxxxxxxxxxxxx" +" xxxxxxxxxxxxxx" +" xxxxxxxxxxxxxx" +" xxxxxxxxxxxxxx" +" xxxxxxxxxxxxxx" +" xxxxxxxxxxxxxx" +" xxxxxxxxxxxx " +" xxxxxxxxxxxx" +" xxxxxxxxxx " +" xxxxxx "}; + +std::map MarkerBitmaps::markerIndex; + +void +MarkerBitmaps::initClass() +{ + createBitmap("CIRCLE_FILLED", 11, 11, 11, circle11_marker); + createBitmap("CIRCLE_FILLED", 13, 13, 13, circle13_marker); + createBitmap("CIRCLE_FILLED", 15, 15, 15, circle15_marker); + + // the built-in bitmaps of Coin + markerIndex [std::make_pair("CIRCLE_FILLED", 9)] = SoMarkerSet::CIRCLE_FILLED_9_9; + markerIndex [std::make_pair("CIRCLE_FILLED", 7)] = SoMarkerSet::CIRCLE_FILLED_7_7; + markerIndex [std::make_pair("CIRCLE_FILLED", 5)] = SoMarkerSet::CIRCLE_FILLED_5_5; +} + +void MarkerBitmaps::createBitmap(const std::string& name, int px, int width, int height, const char* marker) +{ + int byteidx = 0; + const int byteWidth = (width + 7) / 2; + int size = byteWidth * height; + std::vector bitmapbytes(size); + + for (int h = 0; h < height; h++) { + unsigned char bits = 0; + for (int w = 0; w < width; w++) { + if (marker[(h * width) + w] != ' ') { + bits |= (0x80 >> (w % 8)); + } + if ((((w + 1) % 8) == 0) || (w == width - 1)) { + bitmapbytes[byteidx++] = bits; + bits = 0; + } + } + } + + int MY_BITMAP_IDX = SoMarkerSet::getNumDefinedMarkers(); // add at end + SoMarkerSet::addMarker(MY_BITMAP_IDX, SbVec2s(width, height), + &(bitmapbytes[0]), FALSE, TRUE); + + markerIndex[std::make_pair(name, px)] = MY_BITMAP_IDX; +} + +int MarkerBitmaps::getMarkerIndex(const std::string& name, int px) +{ + std::map::iterator it = markerIndex.find(std::make_pair(name, px)); + if (it != markerIndex.end()) { + return it->second; + } + + return static_cast(SoMarkerSet::CIRCLE_FILLED_7_7); +} + +std::list MarkerBitmaps::getSupportedSizes(const std::string& name) +{ + std::list sizes; + for (std::map::iterator it = markerIndex.begin(); it != markerIndex.end(); ++it) { + if (it->first.first == name) + sizes.push_back(it->first.second); + } + return sizes; +} diff --git a/src/Gui/Inventor/MarkerBitmaps.h b/src/Gui/Inventor/MarkerBitmaps.h new file mode 100644 index 000000000..1945ce2d7 --- /dev/null +++ b/src/Gui/Inventor/MarkerBitmaps.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2016 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef GUI_INVENTOR_MARKERBITMAPS_H +#define GUI_INVENTOR_MARKERBITMAPS_H + +#include +#include +#include + +namespace Gui { namespace Inventor { + +class GuiExport MarkerBitmaps { + +public: + static void initClass(); + static int getMarkerIndex(const std::string&, int px); + static std::list getSupportedSizes(const std::string&); + +private: + static void createBitmap(const std::string&, int px, int width, int height, const char* marker); + +private: + typedef std::pair Marker; + static std::map markerIndex; +}; + +} // namespace Inventor + +} // namespace Gui + +#endif // GUI_INVENTOR_MARKERBITMAPS_H + diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index e0d622f8d..f8d864403 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -52,6 +52,7 @@ #include "SoNavigationDragger.h" #include "Inventor/SoDrawingGrid.h" #include "Inventor/SoAutoZoomTranslation.h" +#include "Inventor/MarkerBitmaps.h" #include "propertyeditor/PropertyItem.h" #include "NavigationStyle.h" @@ -110,6 +111,7 @@ void Gui::SoFCDB::init() SoRegPoint ::initClass(); SoDrawingGrid ::initClass(); SoAutoZoomTranslation ::initClass(); + MarkerBitmaps ::initClass(); PropertyItem ::init(); PropertySeparatorItem ::init(); diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.cpp b/src/Mod/Sketcher/Gui/SketcherSettings.cpp index cfc2d4849..9c10869e5 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.cpp +++ b/src/Mod/Sketcher/Gui/SketcherSettings.cpp @@ -33,6 +33,7 @@ #include "TaskSketcherGeneral.h" #include #include +#include using namespace SketcherGui; @@ -120,6 +121,10 @@ void SketcherSettings::saveSettings() ui->checkBoxAdvancedSolverTaskBox->onSave(); form->saveSettings(); + ParameterGrp::handle hViewGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + int markerSize = ui->EditSketcherMarkerSize->itemData(ui->EditSketcherMarkerSize->currentIndex()).toInt(); + hViewGrp->SetInt("EditSketcherMarkerSize", markerSize); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part"); QVariant data = ui->comboBox->itemData(ui->comboBox->currentIndex()); int pattern = data.toInt(); @@ -154,6 +159,16 @@ void SketcherSettings::loadSettings() ui->checkBoxAdvancedSolverTaskBox->onRestore(); form->loadSettings(); + std::list sizes = Gui::Inventor::MarkerBitmaps::getSupportedSizes("CIRCLE_FILLED"); + for (std::list::iterator it = sizes.begin(); it != sizes.end(); ++it) + ui->EditSketcherMarkerSize->addItem(tr("%1 px").arg(*it), *it); + ParameterGrp::handle hViewGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + int markerSize = hViewGrp->GetInt("EditSketcherMarkerSize", 7); + int markerIndex = ui->EditSketcherMarkerSize->findData(QVariant(markerSize)); + if (markerIndex < 0) + markerIndex = 1; + ui->EditSketcherMarkerSize->setCurrentIndex(markerIndex); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part"); int pattern = hGrp->GetInt("GridLinePattern", 0x0f0f); int index = ui->comboBox->findData(QVariant(pattern)); diff --git a/src/Mod/Sketcher/Gui/SketcherSettings.ui b/src/Mod/Sketcher/Gui/SketcherSettings.ui index 5f4449973..eb5c1285b 100644 --- a/src/Mod/Sketcher/Gui/SketcherSettings.ui +++ b/src/Mod/Sketcher/Gui/SketcherSettings.ui @@ -40,7 +40,7 @@ The color of edges being edited - + 255 255 @@ -73,7 +73,7 @@ The color of vertices being edited - + 255 255 @@ -106,7 +106,7 @@ The color of edges being edited - + 255 255 @@ -139,7 +139,7 @@ The color of vertices being edited - + 255 38 @@ -172,7 +172,7 @@ The color of fully constrained geometry in edit mode - + 255 38 @@ -192,7 +192,7 @@ The color of construction geometry in edit mode - + 0 0 @@ -225,7 +225,7 @@ The color of external geometry in edit mode - + 204 51 @@ -271,7 +271,7 @@ The color of fully constrained geometry in edit mode - + 0 255 @@ -397,7 +397,7 @@ - + 0 0 @@ -446,7 +446,7 @@ The color of driving constraints in edit mode - + 255 38 @@ -466,7 +466,7 @@ The color of non-driving constrains or dimensions in edit mode - + 0 38 @@ -493,63 +493,71 @@ - - - - - - 182 - 0 - - - - Font size - - - - - - - px - - - 1 - - - 100 - - - 17 - - - EditSketcherFontSize - - - View - - - - + + + + 182 + 0 + + + + Font size + + + + + + + px + + + 1 + + + 100 + + + 17 + + + EditSketcherFontSize + + + View + + - - - - - Grid line pattern - - - - - - - -1 - - - - + + + + 182 + 0 + + + + Marker size + + + + + + + + Grid line pattern + + + + + + + -1 + + + + Ask for value after creating a distance constraint @@ -565,7 +573,7 @@ - + Geometry Creation "Continue Mode" diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 184983b0b..57760b81e 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -96,6 +96,7 @@ #include #include #include +#include #include #include @@ -155,6 +156,7 @@ struct EditData { PreselectPoint(-1), PreselectCurve(-1), PreselectCross(-1), + MarkerSize(7), blockedPreselection(false), FullyConstrained(false), //ActSketch(0), // if you are wondering, it went to SketchObject, accessible via getSketchObject()->getSolvedSketch() @@ -183,6 +185,7 @@ struct EditData { int PreselectPoint; int PreselectCurve; int PreselectCross; + int MarkerSize; std::set PreselectConstraintSet; bool blockedPreselection; bool FullyConstrained; @@ -1011,9 +1014,8 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor Mode != STATUS_SKETCH_DragConstraint && Mode != STATUS_SKETCH_UseRubberBand) { - SoPickedPoint *pp = this->getPointOnRay(cursorPos, viewer); - preselectChanged = detectPreselection(pp, viewer, cursorPos); - delete pp; + boost::scoped_ptr pp(this->getPointOnRay(cursorPos, viewer)); + preselectChanged = detectPreselection(pp.get(), viewer, cursorPos); } switch (Mode) { @@ -4206,6 +4208,9 @@ bool ViewProviderSketch::setEdit(int ModNum) assert(!edit); edit = new EditData(); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + edit->MarkerSize = hGrp->GetInt("EditSketcherMarkerSize", 7); + createEditInventorNodes(); edit->visibleBeforeEdit = this->isVisible(); this->hide(); // avoid that the wires interfere with the edit lines @@ -4213,7 +4218,6 @@ bool ViewProviderSketch::setEdit(int ModNum) ShowGrid.setValue(true); TightGrid.setValue(false); - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); float transparency; // set the point color @@ -4417,7 +4421,7 @@ void ViewProviderSketch::createEditInventorNodes(void) edit->PointSet = new SoMarkerSet; edit->PointSet->setName("PointSet"); - edit->PointSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7; + edit->PointSet->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex("CIRCLE_FILLED", edit->MarkerSize); pointsRoot->addChild(edit->PointSet); // stuff for the Curves +++++++++++++++++++++++++++++++++++++++