Loading and Displaying a DXF file

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
s4eed
Junior Member
Posts: 18
Joined: Fri Sep 27, 2013 3:23 pm

Loading and Displaying a DXF file

Post by s4eed » Fri Sep 27, 2013 4:52 pm

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 ?

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Loading and Displaying a DXF file

Post by andrew » Fri Sep 27, 2013 5:23 pm

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).

s4eed
Junior Member
Posts: 18
Joined: Fri Sep 27, 2013 3:23 pm

Re: Loading and Displaying a DXF file

Post by s4eed » Fri Sep 27, 2013 5:55 pm

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.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Loading and Displaying a DXF file

Post by andrew » Sat Sep 28, 2013 10:18 am

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.

s4eed
Junior Member
Posts: 18
Joined: Fri Sep 27, 2013 3:23 pm

Re: Loading and Displaying a DXF file

Post by s4eed » Sat Sep 28, 2013 11:08 am

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)

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”