Skip to content

Commit

Permalink
changing selection filter to a list of types, rather than a mask
Browse files Browse the repository at this point in the history
  • Loading branch information
danheeks committed Jun 17, 2020
1 parent 17f9805 commit 28d6ba3
Show file tree
Hide file tree
Showing 30 changed files with 208 additions and 88 deletions.
4 changes: 4 additions & 0 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def LoadConfig(self):

cad.SetBackgroundColor(0, cad.Color(config.ReadInt("BackgroundColor0", cad.Color(230, 255, 255).ref())))
cad.SetBackgroundColor(1, cad.Color(config.ReadInt("BackgroundColor1", cad.Color(255, 255, 255).ref())))
cad.SetCurrentColor(cad.Color(config.ReadInt("CurrentColor", cad.Color(0, 0, 0).ref())))


def GetDefaultDir(self):
Expand Down Expand Up @@ -424,6 +425,9 @@ def OnKeyDown(self, e):
else:
return False
return True

def AddExtraRibbonPages(self, ribbon):
pass

class CopyObjectUndoable(cad.BaseUndoable):
def __init__(self, object, copy_object):
Expand Down
1 change: 1 addition & 0 deletions CAD/CAD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
<ClInclude Include="dxf.h" />
<ClInclude Include="EndedObject.h" />
<ClInclude Include="ExtrudedObj.h" />
<ClInclude Include="Filter.h" />
<ClInclude Include="Grid.h" />
<ClInclude Include="GripData.h" />
<ClInclude Include="Gripper.h" />
Expand Down
5 changes: 3 additions & 2 deletions CAD/CadApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "HILine.h"
#include "HText.h"
#include "HeeksFont.h"
#include "Filter.h"

CCadApp *theApp = new CCadApp;

Expand Down Expand Up @@ -2301,7 +2302,7 @@ IRect CCadApp::PointToPickBox(const IPoint& point)
return IRect(point.x - 5, theApp->m_current_viewport->GetViewportSize().GetHeight() - point.y - 5, 10, 10);
}

void CCadApp::GetObjectsInWindow(const IRect &window, bool only_if_fully_in, bool one_of_each, unsigned int filter, std::list<HeeksObj*> &objects)
void CCadApp::GetObjectsInWindow(const IRect &window, bool only_if_fully_in, bool one_of_each, const CFilter &filter, std::list<HeeksObj*> &objects)
{
if (only_if_fully_in){
// only select objects which are completely within the window
Expand Down Expand Up @@ -2357,7 +2358,7 @@ void CCadApp::GetObjectsInWindow(const IRect &window, bool only_if_fully_in, boo
HeeksObj* object_to_use = NULL;
while (object && (object != theApp))
{
if ((object->GetMarkingMask() & filter) && (object->GetMarkingMask() != 0)){
if (filter.CanTypeBePicked(object->GetType())){
object_to_use = object;
}
object = object->m_owner;
Expand Down
2 changes: 1 addition & 1 deletion CAD/CadApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class CCadApp : public CApp
virtual std::wstring GetResFolder()const;
void get_2d_arc_segments(double xs, double ys, double xe, double ye, double xc, double yc, bool dir, bool want_start, double pixels_per_mm, void(*callbackfunc)(const double* xy));
IRect PointToPickBox(const IPoint& point);
void GetObjectsInWindow(const IRect &window, bool only_if_fully_in, bool one_of_each, unsigned int filter, std::list<HeeksObj*> &objects);
void GetObjectsInWindow(const IRect &window, bool only_if_fully_in, bool one_of_each, const CFilter &filter, std::list<HeeksObj*> &objects);
void ColorPickLowestObjects(IRect window, bool single_picking, std::list<HeeksObj*> &objects);
bool PickPosition(const wchar_t* str, double* pos, void(*callback)(const double*) = NULL);
void glSphere(double radius, const double* pos = NULL);
Expand Down
1 change: 0 additions & 1 deletion CAD/CoordinateSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CoordinateSystem: public HeeksObj

// HeeksObj's virtual functions
int GetType()const{return CoordinateSystemType;}
long GetMarkingMask()const{return MARKING_FILTER_COORDINATE_SYSTEM;}
void glCommands(bool select, bool marked, bool no_color);
void GetBox(CBox &box);
const wchar_t* GetTypeString(void)const{ return L"Coordinate System"; }
Expand Down
19 changes: 19 additions & 0 deletions CAD/Filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <set>

// To support objects from anywhere, which can be added later, I am removing GetMarkingMask for objects.
// Instead, this CFilter class will use the object's GetType
// if there are any types in the set, only those can be picked
// else if types set is empty, any object can be picked
class CFilter
{
std::set<int> m_types;
public:
CFilter(){}
void Clear(){ m_types.clear(); }
void AddType(int type){ m_types.insert(type); }
bool CanTypeBePicked(int type)const{
if (m_types.size() == 0)return true;
return (m_types.find(type) != m_types.end());
}
};
1 change: 0 additions & 1 deletion CAD/HArc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class HArc: public EndedObject{

// HeeksObj's virtual functions
int GetType()const{return ArcType;}
long GetMarkingMask()const{return MARKING_FILTER_ARC;}
int GetIDGroupType()const{return LineType;}
void glCommands(bool select, bool marked, bool no_color);
void GetBox(CBox &box);
Expand Down
1 change: 0 additions & 1 deletion CAD/HCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class HCircle : public ExtrudedObj<IdNamedObj>{

// HeeksObj's virtual functions
int GetType()const{ return CircleType; }
long GetMarkingMask()const{ return MARKING_FILTER_CIRCLE; }
void glCommands(bool select, bool marked, bool no_color);
void GetBox(CBox &box);
const wchar_t* GetTypeString(void)const{ return L"Circle"; }
Expand Down
1 change: 0 additions & 1 deletion CAD/HILine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class HILine: public EndedObject{

// HeeksObj's virtual functions
int GetType()const{return ILineType;}
long GetMarkingMask()const{return MARKING_FILTER_ILINE;}
void glCommands(bool select, bool marked, bool no_color);
void GetBox(CBox &box);
const wchar_t* GetTypeString(void)const{return L"Infinite Line";}
Expand Down
1 change: 0 additions & 1 deletion CAD/HLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class HLine: public EndedObject{

// HeeksObj's virtual functions
int GetType()const{return LineType;}
long GetMarkingMask()const{return MARKING_FILTER_LINE;}
void glCommands(bool select, bool marked, bool no_color);
void GetBox(CBox &box);
const wchar_t* GetTypeString(void)const{return L"Line";}
Expand Down
1 change: 0 additions & 1 deletion CAD/HPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class HPoint: public IdNamedObj{

// HeeksObj's virtual functions
int GetType()const{return PointType;}
long GetMarkingMask()const{return MARKING_FILTER_POINT;}
void glCommands(bool select, bool marked, bool no_color);
void GetBox(CBox &box);
const wchar_t* GetTypeString(void)const{return L"Point";}
Expand Down
1 change: 0 additions & 1 deletion CAD/HText.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class HText: public ObjList {

// HeeksObj's virtual functions
int GetType()const{return TextType;}
long GetMarkingMask()const{return MARKING_FILTER_TEXT;}
void glCommands(bool select, bool marked, bool no_color);
bool DrawAfterOthers(){return true;}
void GetBox(CBox &box);
Expand Down
21 changes: 1 addition & 20 deletions CAD/HeeksObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GripData;
class Matrix;
class Point3d;
class Line;
class CFilter;

// NOTE: If adding to this enumeration, please also add the verbose description to the HeeksCADType() routine
enum{
Expand Down Expand Up @@ -43,25 +44,6 @@ enum{
};



#define MARKING_FILTER_LINE 0x00000001
#define MARKING_FILTER_ARC 0x00000002
#define MARKING_FILTER_ILINE 0x00000004
#define MARKING_FILTER_CIRCLE 0x00000008
#define MARKING_FILTER_POINT 0x00000010
#define MARKING_FILTER_STL_SOLID 0x00000040
#define MARKING_FILTER_SKETCH 0x00000400
#define MARKING_FILTER_IMAGE 0x00000800
#define MARKING_FILTER_COORDINATE_SYSTEM 0x00000800
#define MARKING_FILTER_TEXT 0x00001000
#define MARKING_FILTER_DIMENSION 0x00002000
#define MARKING_FILTER_RULER 0x00004000
#define MARKING_FILTER_GEAR 0x00100000
#define MARKING_FILTER_AREA 0x00200000
#define MARKING_FILTER_UNKNOWN 0x00800000

#define MARKING_FILTER_SKETCH_GROUP (MARKING_FILTER_SKETCH | MARKING_FILTER_AREA | MARKING_FILTER_CIRCLE)

class HeeksObj{
public:
HeeksObj* m_owner;
Expand All @@ -77,7 +59,6 @@ class HeeksObj{

// virtual functions
virtual int GetType()const{return UnknownType;}
virtual long GetMarkingMask()const{return MARKING_FILTER_UNKNOWN;}
virtual int GetIDGroupType()const{return GetType();}
virtual void glCommands(bool select, bool marked, bool no_color){};
virtual bool DrawAfterOthers(){return false;}
Expand Down
31 changes: 30 additions & 1 deletion CAD/PyWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ bool AfterPythonCall(PyObject *main_module)

static std::map<std::string, PyObject*> xml_read_callbacks;
static std::map<std::string, int> custom_object_type_map;
static std::map<std::string, int> filter_object_type_map; // same as custom_object_type_map, but with onyl the objects to add to the filter
static int next_available_custom_object_type = ObjectMaximumType;

HeeksObj* CreatePyObjectWithName(const std::string& name)
Expand All @@ -208,7 +209,7 @@ bool AfterPythonCall(PyObject *main_module)
return object;
}

int RegisterObjectType(std::wstring name, PyObject *callback)
int RegisterObjectType(std::wstring name, PyObject *callback, bool add_to_filter)
{
// registers the Create function to be called in python from CCadApp::CreateObjectOfType
// returns the int type stored by CCadApp
Expand All @@ -220,6 +221,9 @@ bool AfterPythonCall(PyObject *main_module)
xml_read_callbacks.insert(std::make_pair(name_c, callback));
}

if (!add_to_filter)
return 0;

std::map<std::string, int>::iterator FindIt = custom_object_type_map.find(name_c);

if (custom_object_type_map.find(name_c) == custom_object_type_map.end())
Expand All @@ -233,3 +237,28 @@ bool AfterPythonCall(PyObject *main_module)

return FindIt->second;
}


boost::python::list GetObjectNamesAndTypes(void)
{
boost::python::list return_list;

// add the built in types
return_list.append(boost::python::make_tuple(std::wstring(L"Point"), (int)PointType));
return_list.append(boost::python::make_tuple(std::wstring(L"Line"), (int)LineType));
return_list.append(boost::python::make_tuple(std::wstring(L"Arc"), (int)ArcType));
return_list.append(boost::python::make_tuple(std::wstring(L"Infinite Line"), (int)ILineType));
return_list.append(boost::python::make_tuple(std::wstring(L"Circle"), (int)CircleType));
return_list.append(boost::python::make_tuple(std::wstring(L"Sketch"), (int)SketchType));
return_list.append(boost::python::make_tuple(std::wstring(L"STL Solid"), (int)StlSolidType));
return_list.append(boost::python::make_tuple(std::wstring(L"Coordinate System"), (int)CoordinateSystemType));
return_list.append(boost::python::make_tuple(std::wstring(L"Text"), (int)TextType));

// add the custom types
for (std::map<std::string, int>::iterator It = custom_object_type_map.begin(); It != custom_object_type_map.end(); It++)
{
return_list.append(boost::python::make_tuple(It->first, It->second));
}
return return_list;
}

3 changes: 2 additions & 1 deletion CAD/PyWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,5 +672,6 @@ class cad_wrapper : public boost::python::wrapper<T>

void CallPythonCallback(PyObject* callback);
HeeksObj* CreatePyObjectWithName(const std::string& name);
int RegisterObjectType(std::wstring name, PyObject *callback);
int RegisterObjectType(std::wstring name, PyObject *callback = NULL, bool add_to_filter = true);
boost::python::list GetObjectNamesAndTypes(void);

16 changes: 12 additions & 4 deletions CAD/PythonStuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "Gripper.h"
#include "GripperSelTransform.h"
#include "CoordinateSystem.h"
#include "Filter.h"

void OnExit()
{
Expand Down Expand Up @@ -303,6 +304,8 @@ void CadImport(const std::wstring &filepath, HeeksObj* paste_into = NULL)

BOOST_PYTHON_FUNCTION_OVERLOADS(CadImportOverloads, CadImport, 1, 2)

BOOST_PYTHON_FUNCTION_OVERLOADS(RegisterObjectTypeOverloads, RegisterObjectType, 2, 3)

bool CadSaveFile(std::wstring fp)
{
return theApp->SaveFile(fp.c_str());
Expand Down Expand Up @@ -1759,7 +1762,7 @@ void EndDrawing()
theApp->RestoreInputMode();
}

boost::python::list ObjectsUnderWindow(IRect window, bool only_if_fully_in, bool one_of_each, int filter)
boost::python::list ObjectsUnderWindow(IRect window, bool only_if_fully_in, bool one_of_each, const CFilter &filter)
{
window.MakePositive();

Expand Down Expand Up @@ -2233,6 +2236,12 @@ void SetCurrentColor(const HeeksColor& color)
.def_readwrite("height", &IRect::height)
;

boost::python::class_<CFilter>("Filter")
.def("Clear", &CFilter::Clear)
.def("AddType", &CFilter::AddType)
.def("CanTypeBePicked", &CFilter::CanTypeBePicked)
;

boost::python::class_<ObserverWrap, boost::noncopyable >("Observer")
.def(boost::python::init<ObserverWrap>())
;
Expand Down Expand Up @@ -2491,7 +2500,8 @@ void SetCurrentColor(const HeeksColor& color)
boost::python::def("DrawDisableLights", &DrawDeleteList);
boost::python::def("AddProperty", AddProperty);
boost::python::def("GetObjectFromId", &GetObjectFromId);
boost::python::def("RegisterObjectType", RegisterObjectType);
boost::python::def("RegisterObjectType", &RegisterObjectType, RegisterObjectTypeOverloads((boost::python::arg("name"), boost::python::arg("callback"), boost::python::arg("add_to_filter") = true)));
boost::python::def("GetObjectNamesAndTypes", GetObjectNamesAndTypes);
boost::python::def("SetXmlValue", SetXmlValue);
boost::python::def("BeginXmlChild", BeginXmlChild);
boost::python::def("EndXmlChild", EndXmlChild);
Expand Down Expand Up @@ -2647,7 +2657,5 @@ void SetCurrentColor(const HeeksColor& color)
boost::python::scope().attr("PROPERTY_TYPE_CHECK") = (int)CheckPropertyType;
boost::python::scope().attr("PROPERTY_TYPE_LIST") = (int)ListOfPropertyType;
boost::python::scope().attr("PROPERTY_TYPE_FILE") = (int)FilePropertyType;
boost::python::scope().attr("MARKING_FILTER_SKETCH_GROUP") = (int)MARKING_FILTER_SKETCH_GROUP;
boost::python::scope().attr("MARKING_FILTER_STL_SOLID") = (int)MARKING_FILTER_STL_SOLID;

}
1 change: 0 additions & 1 deletion CAD/Ruler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class HRuler: public HeeksObj{

// HeeksObj's virtual functions
int GetType()const{return RulerType;}
long GetMarkingMask()const{return MARKING_FILTER_RULER;}
void glCommands(bool select, bool marked, bool no_color);
void KillGLLists(void);
void GetBox(CBox &box);
Expand Down
1 change: 0 additions & 1 deletion CAD/Sketch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class CSketch:public IdNamedObjList
bool operator!= ( const CSketch & rhs ) const { return(! (*this == rhs)); }

int GetType()const{return SketchType;}
long GetMarkingMask()const{return MARKING_FILTER_SKETCH;}
const wchar_t* GetTypeString(void)const{return L"Sketch";}
const wchar_t* GetIconFilePath();
void GetProperties(std::list<Property *> *list);
Expand Down
1 change: 0 additions & 1 deletion CAD/StlSolid.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class CStlSolid:public HeeksObj{
virtual const CStlSolid& operator=(const CStlSolid& s);

int GetType()const{return StlSolidType;}
long GetMarkingMask()const{return MARKING_FILTER_STL_SOLID;}
const wchar_t* GetTypeString(void)const{return L"STL Solid";}
const wchar_t* GetIconFilePath();
void GetProperties(std::list<Property *> *list);
Expand Down
35 changes: 35 additions & 0 deletions FilterDlg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import wx
import cad
from HDialog import HDialog

class FilterDlg(HDialog):
def __init__(self):
HDialog.__init__(self, title = 'Filter')

self.names_and_types = cad.GetObjectNamesAndTypes()
print(len( self.names_and_types ))
self.check_boxes = []

sizerMain = wx.BoxSizer(wx.VERTICAL)
for name, type in cad.GetObjectNamesAndTypes():
check_box = wx.CheckBox(self, wx.ID_ANY, name)
self.check_boxes.append((check_box, type))
if wx.GetApp().select_mode.filter.CanTypeBePicked(type):
check_box.SetValue(True)
sizerMain.Add(check_box, 0, wx.ALL, 2)

self.MakeOkAndCancel(wx.HORIZONTAL).AddToSizer(sizerMain)

self.SetSizer( sizerMain )
sizerMain.SetSizeHints( self )
sizerMain.Fit( self )

def SetFilterFromCheckBoxes(self):
checked_types = []
for check_box, type in self.check_boxes:
if check_box.IsChecked():
checked_types.append(type)
wx.GetApp().select_mode.filter.Clear()
if len(checked_types) < len(self.names_and_types):
for checked_type in checked_types:
wx.GetApp().select_mode.filter.AddType(checked_type)
7 changes: 6 additions & 1 deletion Frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from InputModeCanvas import InputModeCanvas
from PropertiesCanvas import PropertiesCanvas
from ObjPropsCanvas import ObjPropsCanvas
from Options import Options
import cad
import sys
import os
Expand All @@ -16,6 +15,7 @@
import Gear
from Ribbon import Ribbon
from About import AboutBox
from FilterDlg import FilterDlg

pycad_dir = os.path.dirname(os.path.realpath(__file__))
HEEKS_WILDCARD_STRING = 'Heeks files |*.heeks;*.HEEKS'
Expand Down Expand Up @@ -581,6 +581,11 @@ def OnUpdateDelete(self, e):
def OnSelectMode(self, e):
cad.SetInputMode(wx.GetApp().select_mode)

def OnFilter(self, e):
dlg = FilterDlg()
if dlg.ShowModal() == wx.ID_OK:
dlg.SetFilterFromCheckBoxes()

def OnMagPrevious(self, e):
self.graphics_canvas.viewport.RestorePreviousViewPoint()
self.graphics_canvas.Refresh()
Expand Down
Loading

0 comments on commit 28d6ba3

Please sign in to comment.