This is me just having my version of fun here.
I downloaded a dxf of a bridge, and I thought it be interesting to see if I could figure out what all is going on when the program loads this this up.
There are probably better ways of doing this, but I thought I’d try this for starters.
It seems that the graphics are loaded up on my debug version at /home/jonas/HeeksCAD_Executable_NotTheBestSolution/share/heekscad/bitmaps.
It look like the file icon I was long for “open.png” Just to make sure I drew a little smilley face it using GIMP and tried running my debug version from C::B. Yep… Go the correct file..
So… should be able to search for all occurences of open.png (hopefully it will just be just one).
Ok.. Not that’s curious… I got a big nada… Hmm… tryed a search on “open”. I think I found it.
src/HeeksFrame.cpp|1403|m_toolBar->AddTool(wxID_OPEN, _T(“Open”), ToolImage(_T(“open”)), _(“Open file”));|
Just out of curiosity, I’m curious what kind of error message, I’ll get rename the file so heekscad can’t find it.”
This error message pops up:
Can’t load image from file ‘/home/jonas/HeeksCAD_Executable_NotTheBestSolution/bin/../share/heekscad/bitmaps/open.png’: file does not exist.
Ok.. I guess I should change it back.
So… There’s an object toolimage
So… Here is why the “open.png” search didn’t work
interface/ToolImage.cpp|16|ToolImage::ToolImage(const wxString& name):wxImage(wxGetApp().GetExeFolder() + _T(“/../share/heekscad/bitmaps/”) + name + _T(“.png”), wxBITMAP_TYPE_PNG)|
Here is the object declaration of Toolimage.
class ToolImage: public wxImage{
public:
#ifdef HEEKSCAD
static float m_button_scale;
static const int full_size;
static const int default_bitmap_size;
#endifToolImage(const wxString& name);
static int GetBitmapSize();
#ifdef HEEKSCAD
static void SetBitmapSize(int size);
#endif
};
Ok… So much for ToolImage.
The next thing to search for is the occurrence wxID_OPEN:
src/HeeksFrame.cpp|76|EVT_MENU(wxID_OPEN, CHeeksFrame::OnOpenButton)|
src/HeeksFrame.cpp|179|file_menu->Append( wxID_OPEN, _( “Open” ) );|
src/HeeksFrame.cpp|1403|m_toolBar->AddTool(wxID_OPEN, _T(“Open”), ToolImage(_T(“open”)), _(“Open file”));|
So… I think the next thing I’m looking for is CHeeksFrame::OnOpenButton
src/HeeksFrame.cpp|76|EVT_MENU(wxID_OPEN, CHeeksFrame::OnOpenButton)|
src/HeeksFrame.cpp|753|void CHeeksFrame::OnOpenButton( wxCommandEvent& event )|
Which leads me to this section of code:
void CHeeksFrame::OnOpenButton( wxCommandEvent& event )
{
wxFileDialog dialog(this, _(“Open file”), wxEmptyString, wxEmptyString, wxGetApp().GetKnownFilesWildCardString());
dialog.CentreOnParent();if (dialog.ShowModal() == wxID_OK)
{
if(wxGetApp().CheckForModifiedDoc())
{
wxGetApp().Reset();
wxGetApp().OpenFile(dialog.GetPath().c_str());
wxGetApp().OnNewOrOpen(true);
wxGetApp().SetLikeNewFile();
}
}
}
Which makes me say heh? Good place for me to stop and do something like eat… But first mess with the “Open file” text in wxFileDialog dialog(this, _(“Open file”), to see if I’m where I think I am. This sort like common dialog control in vb but not quite… I need to figure this out to see where this goes next…
A couple things need to be researched:
wxfileDialog and wxGetApp
Googling for wxGetAPP this sort of popped up….
Looks interesting but I need to stay on track: http://www.classes.cs.uchicago.edu/archive/2003/fall/51044-1/sw/wxX11-2.4.2/demos/
Ok…this is off the wxwidgets.org site.
::wxGetApp
wxAppDerivedClass& wxGetApp()
This function doesn’t exist in wxWidgets but it is created by using the IMPLEMENT_APP macro. Thus, before using it anywhere but in the same module where this macro is used, you must make it available using DECLARE_APP.
The advantage of using this function compared to directly using the global wxTheApp pointer is that the latter is of type wxApp * and so wouldn’t allow you to access the functions specific to your application class but not present in wxApp while wxGetApp() returns the object of the right type.
IMPLEMENT_APP(HeeksCADapp) appear in the code. So it appears that the function definitions are called out in HeekCADapp. So I have a trail of breadcrumbs to follow.
I wanted to try a little experiment the code.:
//wxGetApp().Reset();
HeeksCADapp().Reset;
wxGetApp().OpenFile(filepath.c_str());
wxGetApp().OnNewOrOpen(true);
wxGetApp().SetLikeNewFile();
So it got this error when I compiled.
/home/jonas/HeeksCAD/src/HeeksFrame.cpp||In member function ‘void CHeeksFrame::OnRecentFile(wxCommandEvent&)’:|
/home/jonas/HeeksCAD/src/HeeksFrame.cpp|1050|error: statement cannot resolve address of overloaded function|
||=== Build finished: 1 errors, 0 warnings ===|
I need to think about this a little. I’m not understanding something. JTTODO I’ll try to pick that up later.
[Edit 6/11]
Ok… This is going to be one long post. Lets see if I pop off a little here before I go to work.
It appear’s that “HeeksCADapp::Reset()” has a bunch of interesting things going on but are what I’m interested in following at the moment:
void HeeksCADapp::Reset(){
m_marked_list->Clear(true);
m_marked_list->Reset();
std::set::iterator It;
for(It = observers.begin(); It != observers.end(); It++){
Observer *ov = *It;
ov->Clear();
}
Clear();
EndHistory();
delete history;
history = new MainHistory;
m_current_coordinate_system = NULL;
m_doing_rollback = false;
gp_Vec vy(0, 1, 0), vz(0, 0, 1);
m_frame->m_graphics->m_view_point.SetView(vy, vz);
m_filepath = wxString(_(“Untitled”)) + _T(“.heeks”);
m_hidden_for_drag.clear();
m_show_grippers_on_drag = true;
*m_ruler = HRuler();
SetInputMode(m_select_mode);ResetIDs();
}
It think what I’m interested in learning is down this path,”wxGetApp().OnNewOrOpen(true);”
Let’s see what that looks like:
void HeeksCADapp::OnNewOrOpen(bool open)
{
for(std::list::iterator It = m_loaded_libraries.begin(); It != m_loaded_libraries.end(); It++){
wxDynamicLibrary* shared_library = *It;
bool success;
void(*fnOnNewOrOpen)(int) = (void(*)(int))(shared_library->GetSymbol(_T(“OnNewOrOpen”), &success));
if(fnOnNewOrOpen){
(*fnOnNewOrOpen)(open ? 1:0);
}
}
}
Welll…. Ok…. First glance it doesn’t look like we’re doing any dxf”ish. Hmmm devil is in the details.
Wait a second… I think I jumped a little to far ahead… I need to go back to wxGetApp().OpenFile(filepath.c_str());
bool HeeksCADapp::OpenFile(const wxChar *filepath, bool import_not_open, HeeksObj* paste_into)
{
m_in_OpenFile = true;
m_file_open_or_import_type = FileOpenOrImportTypeOther;// returns true if file open was successful
wxString wf(filepath);
wf.LowerCase();bool open_failed = false;
if(import_not_open)StartHistory();
if(wf.EndsWith(_T(“.heeks”)) || wf.EndsWith(_T(“.HEEKS”)))
{
m_file_open_or_import_type = FileOpenOrImportTypeHeeks;
OpenXMLFile(filepath, import_not_open, paste_into);
}
else if(wf.EndsWith(_T(“.svg”)) || wf.EndsWith(_T(“.SVG”)))
{
OpenSVGFile(filepath, import_not_open);
}
else if(wf.EndsWith(_T(“.stl”)) || wf.EndsWith(_T(“.STL”)))
{
OpenSTLFile(filepath, import_not_open);
}
else if(wf.EndsWith(_T(“.dxf”)) || wf.EndsWith(_T(“.DXF”)))
{
m_file_open_or_import_type = FileOpenOrImportTypeDxf;
OpenDXFFile(filepath, import_not_open);
}// check for images
else if(OpenImageFile(filepath, import_not_open))
{
}// check for solid files
else if(CShape::ImportSolidsFile(filepath, import_not_open))
{
}
else
{
// error
wxString str = wxString(_(“Invalid file type chosen”)) + _T(” “) + _(“expecting”) + _T(” “) + GetKnownFilesCommaSeparatedList();
wxMessageBox(str);
open_failed = true;
}if(import_not_open)EndHistory();
if(!open_failed)
{
if(!import_not_open)
{
WereAdded(m_objects);
m_filepath.assign(filepath);
InsertRecentFileItem(filepath);
SetFrameTitle();
}
}m_in_OpenFile = false;
return true;
}
On a side note. I’m just starting to play with code::blocks books marks.
Looking at :
void HeeksCADapp::OpenDXFFile(const wxChar *filepath, bool undoably)
{
HeeksDxfRead dxf_file(filepath);
dxf_file.DoRead(undoably);
}
[edit June 12]
I’m wondering if there is a easier way of doing this.
I guess there is two ways of looking at this. Knowing where you where you started and figure out where your going…. or…. find a particular point in the code and figure out how you got there.
Might as well keep going here:
Searching on “DoRead” I come up with this…
void CDxfRead::DoRead(bool undoably)
{
if(m_fail)return;
get_line();
while(!((*m_ifs).eof()))
{
if(!strcmp(m_str, “0”))
{
get_line();
if(!strcmp(m_str, “LINE”)){
if(!ReadLine(undoably))return;
continue;
}
else if(!strcmp(m_str, “ARC”)){
if(!ReadArc(undoably))return;
continue;
}
else if(!strcmp(m_str, “CIRCLE”)){
if(!ReadCircle(undoably))return;
continue;
}
else if(!strcmp(m_str, “ELLIPSE”)){
if(!ReadEllipse(undoably))return;
continue;
}
else if(!strcmp(m_str, “SPLINE”)){
if(!ReadSpline(undoably))return;
continue;
}
else if(!strcmp(m_str, “LWPOLYLINE”)){
if(!ReadLwPolyLine(undoably))return;
continue;
}
}
get_line();
}
}
I think I jumped a few steps here from but it appears to be stll heeks software ware we’re in…