~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/dxf2shp_converter/dxflib/src/dl_writer_ascii.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** $Id: dl_writer_ascii.cpp 242 2004-04-12 22:39:43Z andrew $
 
3
**
 
4
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
5
** Copyright (C) 2001 Robert J. Campbell Jr.
 
6
**
 
7
** This file is part of the dxflib project.
 
8
**
 
9
** This file may be distributed and/or modified under the terms of the
 
10
** GNU General Public License version 2 as published by the Free Software
 
11
** Foundation and appearing in the file LICENSE.GPL included in the
 
12
** packaging of this file.
 
13
**
 
14
** Licensees holding valid dxflib Professional Edition licenses may use
 
15
** this file in accordance with the dxflib Commercial License
 
16
** Agreement provided with the Software.
 
17
**
 
18
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
19
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
20
**
 
21
** See http://www.ribbonsoft.com for further details.
 
22
**
 
23
** Contact info@ribbonsoft.com if any conditions of this licensing are
 
24
** not clear to you.
 
25
**
 
26
**********************************************************************/
 
27
 
 
28
#include <cstdio>
 
29
#include <cstring>
 
30
 
 
31
#include "dl_writer_ascii.h"
 
32
#include "dl_exception.h"
 
33
 
 
34
 
 
35
/**
 
36
 * Closes the output file.
 
37
 */
 
38
void DL_WriterA::close() const
 
39
{
 
40
  m_ofile.close();
 
41
}
 
42
 
 
43
 
 
44
/**
 
45
 * @retval true Opening file has failed.
 
46
 * @retval false Otherwise.
 
47
 */
 
48
bool DL_WriterA::openFailed() const
 
49
{
 
50
  return m_ofile.fail();
 
51
}
 
52
 
 
53
 
 
54
 
 
55
/**
 
56
 * Writes a real (double) variable to the DXF file.
 
57
 *
 
58
 * @param gc Group code.
 
59
 * @param value Double value
 
60
 */
 
61
void DL_WriterA::dxfReal( int gc, double value ) const
 
62
{
 
63
  char str[256];
 
64
  sprintf( str, "%.16f", value );
 
65
 
 
66
  // fix for german locale:
 
67
  strReplace( str, ',', '.' );
 
68
 
 
69
  // Cut away those zeros at the end:
 
70
  bool dot = false;
 
71
  int end = -1;
 
72
  for ( unsigned int i = 0; i < strlen( str ); ++i )
 
73
  {
 
74
    if ( str[i] == '.' )
 
75
    {
 
76
      dot = true;
 
77
      end = i + 2;
 
78
      continue;
 
79
    }
 
80
    else if ( dot && str[i] != '0' )
 
81
    {
 
82
      end = i + 1;
 
83
    }
 
84
  }
 
85
  if ( end > 0 && end < ( int )strlen( str ) )
 
86
  {
 
87
    str[end] = '\0';
 
88
  }
 
89
 
 
90
  dxfString( gc, str );
 
91
  m_ofile.flush();
 
92
}
 
93
 
 
94
 
 
95
 
 
96
/**
 
97
 * Writes an int variable to the DXF file.
 
98
 *
 
99
 * @param gc Group code.
 
100
 * @param value Int value
 
101
 */
 
102
void DL_WriterA::dxfInt( int gc, int value ) const
 
103
{
 
104
  m_ofile << ( gc < 10 ? "  " : ( gc < 100 ? " " : "" ) ) << gc << "\n"
 
105
  << value << "\n";
 
106
}
 
107
 
 
108
 
 
109
 
 
110
/**
 
111
 * Writes a hex int variable to the DXF file.
 
112
 *
 
113
 * @param gc Group code.
 
114
 * @param value Int value
 
115
 */
 
116
void DL_WriterA::dxfHex( int gc, int value ) const
 
117
{
 
118
  char str[12];
 
119
  sprintf( str, "%0X", value );
 
120
  dxfString( gc, str );
 
121
}
 
122
 
 
123
 
 
124
 
 
125
/**
 
126
 * Writes a string variable to the DXF file.
 
127
 *
 
128
 * @param gc Group code.
 
129
 * @param value String
 
130
 */
 
131
void DL_WriterA::dxfString( int gc, const char* value ) const
 
132
{
 
133
  if ( value == NULL )
 
134
  {
 
135
#ifndef __GCC2x__
 
136
    throw DL_NullStrExc();
 
137
#endif
 
138
  }
 
139
  m_ofile << ( gc < 10 ? "  " : ( gc < 100 ? " " : "" ) ) << gc << "\n"
 
140
  << value << "\n";
 
141
}
 
142
 
 
143
 
 
144
 
 
145
void DL_WriterA::dxfString( int gc, const string& value ) const
 
146
{
 
147
  m_ofile << ( gc < 10 ? "  " : ( gc < 100 ? " " : "" ) ) << gc << "\n"
 
148
  << value << "\n";
 
149
}
 
150
 
 
151
 
 
152
/**
 
153
 * Replaces every occurence of src with dest in the null terminated str.
 
154
 */
 
155
void DL_WriterA::strReplace( char* str, char src, char dest )
 
156
{
 
157
  size_t i;
 
158
  for ( i = 0; i < strlen( str ); i++ )
 
159
  {
 
160
    if ( str[i] == src )
 
161
    {
 
162
      str[i] = dest;
 
163
    }
 
164
  }
 
165
}
 
166