| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (C) 1995-96 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| Classes: |
| 44 |
| SoAsciiTextV2 |
| 45 |
| |
| 46 |
| Authors: David Mott |
| 47 |
| |
| 48 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 49 |
_______________________________________________________________________ |
| 50 |
*/ |
| 51 |
|
| 52 |
#include <Inventor/actions/SoWriteAction.h> |
| 53 |
#include <Inventor/nodes/SoText3.h> |
| 54 |
#include "SoAsciiTextV2.h" |
| 55 |
#include "Util.h" |
| 56 |
|
| 57 |
SO_NODE_SOURCE(SoAsciiTextV2); |
| 58 |
|
| 59 |
//////////////////////////////////////////////////////////////////////// |
| 60 |
// |
| 61 |
// Description: |
| 62 |
// init that class! |
| 63 |
// |
| 64 |
void |
| 65 |
SoAsciiTextV2::initClass() |
| 66 |
// |
| 67 |
//////////////////////////////////////////////////////////////////////// |
| 68 |
{ |
| 69 |
SO__NODE_INIT_CLASS(SoAsciiTextV2, "AsciiText", SoAsciiText); |
| 70 |
|
| 71 |
// Tell the type system whenever it wants to create something |
| 72 |
// of type SoAsciiText to create a SoAsciiTextV2 |
| 73 |
SoType::overrideType( |
| 74 |
SoAsciiText::getClassTypeId(), &SoAsciiTextV2::createInstance); |
| 75 |
} |
| 76 |
|
| 77 |
//////////////////////////////////////////////////////////////////////// |
| 78 |
// |
| 79 |
// Description: |
| 80 |
// Constructor |
| 81 |
// |
| 82 |
SoAsciiTextV2::SoAsciiTextV2() |
| 83 |
// |
| 84 |
//////////////////////////////////////////////////////////////////////// |
| 85 |
{ |
| 86 |
SO_NODE_CONSTRUCTOR(SoAsciiTextV2); |
| 87 |
SO_NODE_ADD_FIELD(alternateRep, (NULL)); |
| 88 |
} |
| 89 |
|
| 90 |
//////////////////////////////////////////////////////////////////////// |
| 91 |
// |
| 92 |
// Description: |
| 93 |
// Destructor |
| 94 |
// |
| 95 |
SoAsciiTextV2::~SoAsciiTextV2() |
| 96 |
// |
| 97 |
//////////////////////////////////////////////////////////////////////// |
| 98 |
{ |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
//////////////////////////////////////////////////////////////////////// |
| 103 |
// |
| 104 |
// Description: |
| 105 |
// Convert to a Text3 node |
| 106 |
// |
| 107 |
// static public |
| 108 |
// |
| 109 |
SoText3 * |
| 110 |
SoAsciiTextV2::convert(SoAsciiTextV2 *asciiText) |
| 111 |
// |
| 112 |
//////////////////////////////////////////////////////////////////////// |
| 113 |
{ |
| 114 |
SoText3 *text3 = new SoText3; |
| 115 |
|
| 116 |
// Copy field values from AsciiText to the alternate rep Text3 |
| 117 |
COPY_FIELD(text3, asciiText, string); // text3->string = asciiText->string |
| 118 |
COPY_FIELD(text3, asciiText, spacing); // text3->spacing = asciiText->spacing |
| 119 |
|
| 120 |
if (! asciiText->justification.isDefault()) { |
| 121 |
SoText3::Justification just; |
| 122 |
switch (asciiText->justification.getValue()) { |
| 123 |
case SoAsciiText::LEFT: just = SoText3::LEFT; break; |
| 124 |
case SoAsciiText::RIGHT: just = SoText3::RIGHT; break; |
| 125 |
case SoAsciiText::CENTER: just = SoText3::CENTER; break; |
| 126 |
} |
| 127 |
text3->justification = just; |
| 128 |
} |
| 129 |
|
| 130 |
text3->parts = SoText3::FRONT; |
| 131 |
|
| 132 |
//??? what do we do with SoAsciiText::width field? |
| 133 |
|
| 134 |
return text3; |
| 135 |
} |
| 136 |
|
| 137 |
//////////////////////////////////////////////////////////////////////// |
| 138 |
// |
| 139 |
// Description: |
| 140 |
// Convert to a Text3 node (same as above routine, but takes SoAsciiText! |
| 141 |
// |
| 142 |
// static public |
| 143 |
// |
| 144 |
SoText3 * |
| 145 |
SoAsciiTextV2::convert(SoAsciiText *asciiText) |
| 146 |
// |
| 147 |
//////////////////////////////////////////////////////////////////////// |
| 148 |
{ |
| 149 |
SoText3 *text3 = new SoText3; |
| 150 |
|
| 151 |
// Copy field values from AsciiText to the alternate rep Text3 |
| 152 |
COPY_FIELD(text3, asciiText, string); // text3->string = asciiText->string |
| 153 |
COPY_FIELD(text3, asciiText, spacing); // text3->spacing = asciiText->spacing |
| 154 |
|
| 155 |
if (! asciiText->justification.isDefault()) { |
| 156 |
SoText3::Justification just; |
| 157 |
switch (asciiText->justification.getValue()) { |
| 158 |
case SoAsciiText::LEFT: just = SoText3::LEFT; break; |
| 159 |
case SoAsciiText::RIGHT: just = SoText3::RIGHT; break; |
| 160 |
case SoAsciiText::CENTER: just = SoText3::CENTER; break; |
| 161 |
} |
| 162 |
text3->justification = just; |
| 163 |
} |
| 164 |
|
| 165 |
text3->parts = SoText3::FRONT; |
| 166 |
|
| 167 |
//??? what do we do with SoAsciiText::width field? |
| 168 |
|
| 169 |
return text3; |
| 170 |
} |
| 171 |
|
| 172 |
//////////////////////////////////////////////////////////////////////// |
| 173 |
// |
| 174 |
// Description: |
| 175 |
// write the alternate rep for this node |
| 176 |
// |
| 177 |
void |
| 178 |
SoAsciiTextV2::write(SoWriteAction *action) |
| 179 |
// |
| 180 |
//////////////////////////////////////////////////////////////////////// |
| 181 |
{ |
| 182 |
SoOutput *out = action->getOutput(); |
| 183 |
|
| 184 |
// In write-reference counting phase |
| 185 |
if (out->getStage() == SoOutput::COUNT_REFS) { |
| 186 |
// Only do this once! |
| 187 |
if (alternateRep.isDefault()) { |
| 188 |
alternateRep = SoAsciiTextV2::convert(this); |
| 189 |
|
| 190 |
// Inventor V2.0 cannot read unknown nodes with SoSFEnum fields. |
| 191 |
// Don't let any enums get written out. |
| 192 |
// NOTE: a better solution might be to write the enum as a string, |
| 193 |
// and have the upgrader for this node convert that string back |
| 194 |
// to an enum value. But this bug was found too close to the 2.1 MR date |
| 195 |
// to do that more complicated fix. Instead, just don't write the enum. |
| 196 |
justification.setDefault(TRUE); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
SoAsciiText::write(action); |
| 201 |
} |
| 202 |
|