Skip to content

Commit

Permalink
+ issue #1203: Allow User to Adjust Size of Constraint Points
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 7, 2016
1 parent 4672066 commit 4fcb93b
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 70 deletions.
2 changes: 2 additions & 0 deletions src/Gui/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -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
Expand Down
176 changes: 176 additions & 0 deletions src/Gui/Inventor/MarkerBitmaps.cpp
@@ -0,0 +1,176 @@
/***************************************************************************
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Inventor/nodes/SoMarkerSet.h>
#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::Marker, int> 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<unsigned char> 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<Marker, int>::iterator it = markerIndex.find(std::make_pair(name, px));
if (it != markerIndex.end()) {
return it->second;
}

return static_cast<int>(SoMarkerSet::CIRCLE_FILLED_7_7);
}

std::list<int> MarkerBitmaps::getSupportedSizes(const std::string& name)
{
std::list<int> sizes;
for (std::map<Marker, int>::iterator it = markerIndex.begin(); it != markerIndex.end(); ++it) {
if (it->first.first == name)
sizes.push_back(it->first.second);
}
return sizes;
}
53 changes: 53 additions & 0 deletions src/Gui/Inventor/MarkerBitmaps.h
@@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <string>
#include <list>
#include <map>

namespace Gui { namespace Inventor {

class GuiExport MarkerBitmaps {

public:
static void initClass();
static int getMarkerIndex(const std::string&, int px);
static std::list<int> getSupportedSizes(const std::string&);

private:
static void createBitmap(const std::string&, int px, int width, int height, const char* marker);

private:
typedef std::pair<std::string, int> Marker;
static std::map<Marker, int> markerIndex;
};

} // namespace Inventor

} // namespace Gui

#endif // GUI_INVENTOR_MARKERBITMAPS_H

2 changes: 2 additions & 0 deletions src/Gui/SoFCDB.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -110,6 +111,7 @@ void Gui::SoFCDB::init()
SoRegPoint ::initClass();
SoDrawingGrid ::initClass();
SoAutoZoomTranslation ::initClass();
MarkerBitmaps ::initClass();

PropertyItem ::init();
PropertySeparatorItem ::init();
Expand Down
15 changes: 15 additions & 0 deletions src/Mod/Sketcher/Gui/SketcherSettings.cpp
Expand Up @@ -33,6 +33,7 @@
#include "TaskSketcherGeneral.h"
#include <App/Application.h>
#include <Gui/PrefWidgets.h>
#include <Gui/Inventor/MarkerBitmaps.h>

using namespace SketcherGui;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -154,6 +159,16 @@ void SketcherSettings::loadSettings()
ui->checkBoxAdvancedSolverTaskBox->onRestore();
form->loadSettings();

std::list<int> sizes = Gui::Inventor::MarkerBitmaps::getSupportedSizes("CIRCLE_FILLED");
for (std::list<int>::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));
Expand Down

0 comments on commit 4fcb93b

Please sign in to comment.