libDXF 0.0.1
A library with DXF related functions written in C.

drawing.c

Go to the documentation of this file.
00001 
00035 #include "drawing.h"
00036 
00037 
00046 DxfDrawing *
00047 dxf_drawing_new ()
00048 {
00049 #if DEBUG
00050         DXF_DEBUG_BEGIN
00051 #endif
00052         DxfDrawing *drawing = NULL;
00053         size_t size;
00054 
00055         size = sizeof (DxfDrawing);
00056         /* avoid malloc of 0 bytes */
00057         if (size == 0) size = 1;
00058         if ((drawing = malloc (size)) == NULL)
00059         {
00060                 fprintf (stderr,
00061                   (_("Error in %s () could not allocate memory for a DxfDrawing struct.\n")),
00062                   __FUNCTION__);
00063                 drawing = NULL;
00064         }
00065         else
00066         {
00067                 memset (drawing, 0, size);
00068         }
00069 #if DEBUG
00070         DXF_DEBUG_END
00071 #endif
00072         return (drawing);
00073 }
00074 
00075 
00082 DxfDrawing *
00083 dxf_drawing_init
00084 (
00085         DxfDrawing *drawing,
00087         int acad_version_number
00089 )
00090 {
00091 #if DEBUG
00092         DXF_DEBUG_BEGIN
00093 #endif
00094         /* Do some basic checks. */
00095         if (drawing == NULL)
00096         {
00097                 fprintf (stderr,
00098                   (_("Warning in %s () a NULL pointer was passed.\n")),
00099                   __FUNCTION__);
00100                 drawing = dxf_drawing_new ();
00101         }
00102         if (drawing == NULL)
00103         {
00104                 fprintf (stderr,
00105                   (_("Error in %s () could not allocate memory for a DxfDrawing struct.\n")),
00106                   __FUNCTION__);
00107                 return (NULL);
00108         }
00109         dxf_header_init ((DxfHeader *) drawing->header, acad_version_number);
00110         dxf_class_init ((DxfClass *) drawing->class_list);
00111         dxf_block_init ((DxfBlock *) drawing->block_list);
00112         //dxf_entities_init ((DxfEntities *) drawing->entities_list);
00113         dxf_object_init ((DxfObject *) drawing->object_list);
00114         dxf_thumbnail_init ((DxfThumbnail *) drawing->thumbnail);
00115 #if DEBUG
00116         DXF_DEBUG_END
00117 #endif
00118         return (drawing);
00119 }
00120 
00121 
00129 int
00130 dxf_drawing_free
00131 (
00132         DxfDrawing *drawing
00135 )
00136 {
00137 #if DEBUG
00138         DXF_DEBUG_BEGIN
00139 #endif
00140         /* Do some basic checks. */
00141         if (drawing == NULL)
00142         {
00143                 fprintf (stderr,
00144                   (_("Error in %s () a NULL pointer was passed.\n")),
00145                   __FUNCTION__);
00146                 return (EXIT_FAILURE);
00147         }
00148         dxf_header_free ((DxfHeader *) drawing->header);
00149         dxf_class_free_chain ((DxfClass *) drawing->class_list);
00150         dxf_block_free_chain ((DxfBlock *) drawing->block_list);
00151         //dxf_entities_free_chain ((DxfEntities *) drawing->entities_list);
00152         dxf_object_free_chain ((DxfObject *) drawing->object_list);
00153         dxf_thumbnail_free ((DxfThumbnail *) drawing->thumbnail);
00154         free (drawing);
00155         drawing = NULL;
00156 #if DEBUG
00157         DXF_DEBUG_END
00158 #endif
00159         return (EXIT_SUCCESS);
00160 }
00161 
00162 
00168 DxfHeader *
00169 dxf_drawing_get_header
00170 (
00171         DxfDrawing *drawing
00173 )
00174 {
00175 #if DEBUG
00176         DXF_DEBUG_BEGIN
00177 #endif
00178         DxfHeader *result = NULL;
00179 
00180         /* Do some basic checks. */
00181         if (drawing == NULL)
00182         {
00183                 fprintf (stderr,
00184                   (_("Error in %s () a NULL pointer was passed.\n")),
00185                   __FUNCTION__);
00186                 return (NULL);
00187         }
00188         if (drawing->header ==  NULL)
00189         {
00190                 fprintf (stderr,
00191                   (_("Error in %s () a NULL pointer was found in the header member.\n")),
00192                   __FUNCTION__);
00193                 return (NULL);
00194         }
00195         result = (DxfHeader *) drawing->header;
00196 #if DEBUG
00197         DXF_DEBUG_END
00198 #endif
00199         return (result);
00200 }
00201 
00202 
00209 DxfDrawing *
00210 dxf_drawing_set_header
00211 (
00212         DxfDrawing *drawing,
00214         DxfHeader *header
00217 )
00218 {
00219 #if DEBUG
00220         DXF_DEBUG_BEGIN
00221 #endif
00222         /* Do some basic checks. */
00223         if (drawing == NULL)
00224         {
00225                 fprintf (stderr,
00226                   (_("Error in %s () a NULL pointer was passed.\n")),
00227                   __FUNCTION__);
00228                 return (NULL);
00229         }
00230         if (header == NULL)
00231         {
00232                 fprintf (stderr,
00233                   (_("Error in %s () a NULL pointer was passed.\n")),
00234                   __FUNCTION__);
00235                 return (NULL);
00236         }
00237         drawing->header = (struct DxfHeader *) header;
00238 #if DEBUG
00239         DXF_DEBUG_END
00240 #endif
00241         return (drawing);
00242 }
00243 
00244 
00250 DxfClass *
00251 dxf_drawing_get_class_list
00252 (
00253         DxfDrawing *drawing
00255 )
00256 {
00257 #if DEBUG
00258         DXF_DEBUG_BEGIN
00259 #endif
00260         DxfClass *result = NULL;
00261 
00262         /* Do some basic checks. */
00263         if (drawing == NULL)
00264         {
00265                 fprintf (stderr,
00266                   (_("Error in %s () a NULL pointer was passed.\n")),
00267                   __FUNCTION__);
00268                 return (NULL);
00269         }
00270         if (drawing->class_list ==  NULL)
00271         {
00272                 fprintf (stderr,
00273                   (_("Error in %s () a NULL pointer was found in the class_list member.\n")),
00274                   __FUNCTION__);
00275                 return (NULL);
00276         }
00277         result = (DxfClass *) drawing->class_list;
00278 #if DEBUG
00279         DXF_DEBUG_END
00280 #endif
00281         return (result);
00282 }
00283 
00284 
00291 DxfDrawing *
00292 dxf_drawing_set_class_list
00293 (
00294         DxfDrawing *drawing,
00296         DxfClass *class_list
00299 )
00300 {
00301 #if DEBUG
00302         DXF_DEBUG_BEGIN
00303 #endif
00304         /* Do some basic checks. */
00305         if (drawing == NULL)
00306         {
00307                 fprintf (stderr,
00308                   (_("Error in %s () a NULL pointer was passed.\n")),
00309                   __FUNCTION__);
00310                 return (NULL);
00311         }
00312         if (class_list == NULL)
00313         {
00314                 fprintf (stderr,
00315                   (_("Error in %s () a NULL pointer was passed.\n")),
00316                   __FUNCTION__);
00317                 return (NULL);
00318         }
00319         drawing->class_list = (struct DxfClass *) class_list;
00320 #if DEBUG
00321         DXF_DEBUG_END
00322 #endif
00323         return (drawing);
00324 }
00325 
00326 
00332 DxfTables *
00333 dxf_drawing_get_tables_list
00334 (
00335         DxfDrawing *drawing
00337 )
00338 {
00339 #if DEBUG
00340         DXF_DEBUG_BEGIN
00341 #endif
00342         DxfTables *result = NULL;
00343 
00344         /* Do some basic checks. */
00345         if (drawing == NULL)
00346         {
00347                 fprintf (stderr,
00348                   (_("Error in %s () a NULL pointer was passed.\n")),
00349                   __FUNCTION__);
00350                 return (NULL);
00351         }
00352         if (drawing->tables_list ==  NULL)
00353         {
00354                 fprintf (stderr,
00355                   (_("Error in %s () a NULL pointer was found in the tables_list member.\n")),
00356                   __FUNCTION__);
00357                 return (NULL);
00358         }
00359         result = (DxfTables *) drawing->tables_list;
00360 #if DEBUG
00361         DXF_DEBUG_END
00362 #endif
00363         return (result);
00364 }
00365 
00366 
00373 DxfDrawing *
00374 dxf_drawing_set_tables_list
00375 (
00376         DxfDrawing *drawing,
00378         DxfTables *tables_list
00381 )
00382 {
00383 #if DEBUG
00384         DXF_DEBUG_BEGIN
00385 #endif
00386         /* Do some basic checks. */
00387         if (drawing == NULL)
00388         {
00389                 fprintf (stderr,
00390                   (_("Error in %s () a NULL pointer was passed.\n")),
00391                   __FUNCTION__);
00392                 return (NULL);
00393         }
00394         if (tables_list == NULL)
00395         {
00396                 fprintf (stderr,
00397                   (_("Error in %s () a NULL pointer was passed.\n")),
00398                   __FUNCTION__);
00399                 return (NULL);
00400         }
00401         drawing->tables_list = (struct DxfTables *) tables_list;
00402 #if DEBUG
00403         DXF_DEBUG_END
00404 #endif
00405         return (drawing);
00406 }
00407 
00408 
00414 DxfBlock *
00415 dxf_drawing_get_block_list
00416 (
00417         DxfDrawing *drawing
00419 )
00420 {
00421 #if DEBUG
00422         DXF_DEBUG_BEGIN
00423 #endif
00424         DxfBlock *result = NULL;
00425 
00426         /* Do some basic checks. */
00427         if (drawing == NULL)
00428         {
00429                 fprintf (stderr,
00430                   (_("Error in %s () a NULL pointer was passed.\n")),
00431                   __FUNCTION__);
00432                 return (NULL);
00433         }
00434         if (drawing->block_list ==  NULL)
00435         {
00436                 fprintf (stderr,
00437                   (_("Error in %s () a NULL pointer was found in the block_list member.\n")),
00438                   __FUNCTION__);
00439                 return (NULL);
00440         }
00441         result = (DxfBlock *) drawing->block_list;
00442 #if DEBUG
00443         DXF_DEBUG_END
00444 #endif
00445         return (result);
00446 }
00447 
00448 
00455 DxfDrawing *
00456 dxf_drawing_set_block_list
00457 (
00458         DxfDrawing *drawing,
00460         DxfBlock *block_list
00463 )
00464 {
00465 #if DEBUG
00466         DXF_DEBUG_BEGIN
00467 #endif
00468         /* Do some basic checks. */
00469         if (drawing == NULL)
00470         {
00471                 fprintf (stderr,
00472                   (_("Error in %s () a NULL pointer was passed.\n")),
00473                   __FUNCTION__);
00474                 return (NULL);
00475         }
00476         if (block_list == NULL)
00477         {
00478                 fprintf (stderr,
00479                   (_("Error in %s () a NULL pointer was passed.\n")),
00480                   __FUNCTION__);
00481                 return (NULL);
00482         }
00483         drawing->block_list = (struct DxfBlock *) block_list;
00484 #if DEBUG
00485         DXF_DEBUG_END
00486 #endif
00487         return (drawing);
00488 }
00489 
00490 
00497 DxfEntities *
00498 dxf_drawing_get_entities_list
00499 (
00500         DxfDrawing *drawing
00502 )
00503 {
00504 #if DEBUG
00505         DXF_DEBUG_BEGIN
00506 #endif
00507         DxfEntities *result = NULL;
00508 
00509         /* Do some basic checks. */
00510         if (drawing == NULL)
00511         {
00512                 fprintf (stderr,
00513                   (_("Error in %s () a NULL pointer was passed.\n")),
00514                   __FUNCTION__);
00515                 return (NULL);
00516         }
00517         if (drawing->entities_list ==  NULL)
00518         {
00519                 fprintf (stderr,
00520                   (_("Error in %s () a NULL pointer was found in the entities_list member.\n")),
00521                   __FUNCTION__);
00522                 return (NULL);
00523         }
00524         result = (DxfEntities *) drawing->entities_list;
00525 #if DEBUG
00526         DXF_DEBUG_END
00527 #endif
00528         return (result);
00529 }
00530 
00531 
00538 DxfDrawing *
00539 dxf_drawing_set_entities_list
00540 (
00541         DxfDrawing *drawing,
00543         DxfEntities *entities_list
00546 )
00547 {
00548 #if DEBUG
00549         DXF_DEBUG_BEGIN
00550 #endif
00551         /* Do some basic checks. */
00552         if (drawing == NULL)
00553         {
00554                 fprintf (stderr,
00555                   (_("Error in %s () a NULL pointer was passed.\n")),
00556                   __FUNCTION__);
00557                 return (NULL);
00558         }
00559         if (entities_list == NULL)
00560         {
00561                 fprintf (stderr,
00562                   (_("Error in %s () a NULL pointer was passed.\n")),
00563                   __FUNCTION__);
00564                 return (NULL);
00565         }
00566         drawing->entities_list = (struct DxfEntities *) entities_list;
00567 #if DEBUG
00568         DXF_DEBUG_END
00569 #endif
00570         return (drawing);
00571 }
00572 
00573 
00580 DxfObject *
00581 dxf_drawing_get_object_list
00582 (
00583         DxfDrawing *drawing
00585 )
00586 {
00587 #if DEBUG
00588         DXF_DEBUG_BEGIN
00589 #endif
00590         DxfObject *result = NULL;
00591 
00592         /* Do some basic checks. */
00593         if (drawing == NULL)
00594         {
00595                 fprintf (stderr,
00596                   (_("Error in %s () a NULL pointer was passed.\n")),
00597                   __FUNCTION__);
00598                 return (NULL);
00599         }
00600         if (drawing->object_list ==  NULL)
00601         {
00602                 fprintf (stderr,
00603                   (_("Error in %s () a NULL pointer was found in the object_list member.\n")),
00604                   __FUNCTION__);
00605                 return (NULL);
00606         }
00607         result = (DxfObject *) drawing->object_list;
00608 #if DEBUG
00609         DXF_DEBUG_END
00610 #endif
00611         return (result);
00612 }
00613 
00614 
00621 DxfDrawing *
00622 dxf_drawing_set_object_list
00623 (
00624         DxfDrawing *drawing,
00626         DxfObject *object_list
00629 )
00630 {
00631 #if DEBUG
00632         DXF_DEBUG_BEGIN
00633 #endif
00634         /* Do some basic checks. */
00635         if (drawing == NULL)
00636         {
00637                 fprintf (stderr,
00638                   (_("Error in %s () a NULL pointer was passed.\n")),
00639                   __FUNCTION__);
00640                 return (NULL);
00641         }
00642         if (object_list == NULL)
00643         {
00644                 fprintf (stderr,
00645                   (_("Error in %s () a NULL pointer was passed.\n")),
00646                   __FUNCTION__);
00647                 return (NULL);
00648         }
00649         drawing->object_list = (struct DxfObject *) object_list;
00650 #if DEBUG
00651         DXF_DEBUG_END
00652 #endif
00653         return (drawing);
00654 }
00655 
00656 
00662 DxfThumbnail *
00663 dxf_drawing_get_thumbnail
00664 (
00665         DxfDrawing *drawing
00667 )
00668 {
00669 #if DEBUG
00670         DXF_DEBUG_BEGIN
00671 #endif
00672         DxfThumbnail *result = NULL;
00673 
00674         /* Do some basic checks. */
00675         if (drawing == NULL)
00676         {
00677                 fprintf (stderr,
00678                   (_("Error in %s () a NULL pointer was passed.\n")),
00679                   __FUNCTION__);
00680                 return (NULL);
00681         }
00682         if (drawing->thumbnail ==  NULL)
00683         {
00684                 fprintf (stderr,
00685                   (_("Error in %s () a NULL pointer was found in the thumbnail member.\n")),
00686                   __FUNCTION__);
00687                 return (NULL);
00688         }
00689         result = (DxfThumbnail *) drawing->thumbnail;
00690 #if DEBUG
00691         DXF_DEBUG_END
00692 #endif
00693         return (result);
00694 }
00695 
00696 
00703 DxfDrawing *
00704 dxf_drawing_set_thumbnail
00705 (
00706         DxfDrawing *drawing,
00708         DxfThumbnail *thumbnail
00711 )
00712 {
00713 #if DEBUG
00714         DXF_DEBUG_BEGIN
00715 #endif
00716         /* Do some basic checks. */
00717         if (drawing == NULL)
00718         {
00719                 fprintf (stderr,
00720                   (_("Error in %s () a NULL pointer was passed.\n")),
00721                   __FUNCTION__);
00722                 return (NULL);
00723         }
00724         if (thumbnail == NULL)
00725         {
00726                 fprintf (stderr,
00727                   (_("Error in %s () a NULL pointer was passed.\n")),
00728                   __FUNCTION__);
00729                 return (NULL);
00730         }
00731         drawing->thumbnail = (struct DxfThumbnail *) thumbnail;
00732 #if DEBUG
00733         DXF_DEBUG_END
00734 #endif
00735         return (drawing);
00736 }
00737 
00738 
00739 /* EOF*/