Page 1 of 1

Loading and Displaying a DXF file

Posted: Fri Sep 27, 2013 4:52 pm
by s4eed
I'm just playing with QCad source code because I'm a Qt programmer and I found this code really interesting and strong.
I want to load and display a .dxf file in a GraphicsViewQt . I used this code but I got a black screen :

Code: Select all

	RMemoryStorage* storage = new RMemoryStorage();
	RSpatialIndexNavel* spatialIndex = new RSpatialIndexNavel();
	RDocument * document = new RDocument(*storage, *spatialIndex);
	RGraphicsViewQt *view = new RGraphicsViewQt;
	
	RDocumentInterface * documentInterface = new RDocumentInterface(*document);
	documentInterface->importFile("2.dxf", "DXF 2000");

	RGraphicsSceneQt *scene = new RGraphicsSceneQt(*documentInterface);
	view->setScene(scene);
	view->show();
What's wrong with my code ?

Re: Loading and Displaying a DXF file

Posted: Fri Sep 27, 2013 5:23 pm
by andrew
The code looks fine and is almost complete.

First, please make sure that the DXF file can be found and there are no other errors. The return value of importFile should be 0, if the import was successful.

After the import, the scenes and views have to be regenerated with:
documentInterface.regenerateScenes();
Performing an auto zoom is usually also a good idea:
documentInterface.autoZoom();
May I ask, why you are experimenting with QCAD code in C++, not ECMAScript (JavaScript)? I'd highly recommend to use ECMAScript to extend QCAD or to build new applications based on QCAD technology.

This simple example could look like this in ECMAScript (as standalone application):

File 'dummy.js':
var storage = new RMemoryStorage();
var spatialIndex = new RSpatialIndexNavel();
var document = new RDocument(storage, spatialIndex);
var view = new RGraphicsViewQt();

var documentInterface = new RDocumentInterface(document);

var scene = new RGraphicsSceneQt(documentInterface);
view.setScene(scene);
view.show();

documentInterface.importFile("/path/to/file/dummy.dxf", "DXF 2000");
documentInterface.regenerateScenes();
documentInterface.autoZoom();

QCoreApplication.exec();
It can be run like this:
./qcad -autostart dummy.js
Scripts can access the entire API of QCAD and almost all of Qt. Using C++, you would likely sooner or later get to a point where you would have to re-implement some of the QCAD code written in ECMAScript (most of the user interface related code, all of the tools and most widgets are implemented in ECMAScript).

Re: Loading and Displaying a DXF file

Posted: Fri Sep 27, 2013 5:55 pm
by s4eed
Really thank you.
The error code is ‡IoErrorNoImporterFound. How to register a DXF importer?
Honestly I just wanted the DXF importing and displaying of this project. So I tried to just use cpp files related to this purpose . I tried to add them to a new project and compiled them.
But now I eagerly want to find out how this project is organized. Although I'm Qt expert but I don't know any thing about scripting and its power. Does this nice project have any developer documentation? Is it possible to be one of its developers? I think this project is really great. Its structure, its design and its framework.

Re: Loading and Displaying a DXF file

Posted: Sat Sep 28, 2013 10:18 am
by andrew
s4eed wrote:The error code is ‡IoErrorNoImporterFound. How to register a DXF importer?
If you're creating a standalone application in C++ that does not require QCAD, you will have to load the plugins explicitly, for example in your main:
RPluginLoader::loadPlugins(true);
This will load all plugins available in ./plugins. You can for example copy the plugins included with QCAD into your local ./plugins directory for DXF and DWG support.
s4eed wrote:Does this nice project have any developer documentation?
All official documentation is linked from this site:
http://qcad.org/en/qcad-documentation

API and other developer documentation can be found at:
http://qcad.org/doc/qcad/latest/developer/
s4eed wrote:Is it possible to be one of its developers? I think this project is really great. Its structure, its design and its framework.
Yes, of course!
QCAD is available under GPLv3 with exceptions which allow proprietary plugins and add-ons.
If you agree to these terms, you can contribute to QCAD in various ways such as C++ development, ECMAScript development, bug fixing, translations, etc. Here's a brief overview over the areas in which contributions are possible:
http://qcad.org/en/contribute

Welcome aboard :) Don't hesitate to post to the forum if you have any questions.

Re: Loading and Displaying a DXF file

Posted: Sat Sep 28, 2013 11:08 am
by s4eed
You're AWESOME :D
I'm really happy to be here. I've lots of questions. :D I ask them in a new topic in order to respect to the forum rules ! 8)