Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 /* 00039 * Copyright (C) 1990,91 Silicon Graphics, Inc. 00040 * 00041 _______________________________________________________________________ 00042 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00043 | 00044 | $Revision: 1.1.1.1 $ 00045 | 00046 | Description: 00047 | Defines the SoField class, which is the base class for all fields. 00048 | 00049 | Author(s) : Paul S. Strauss, Nick Thompson, Gavin Bell 00050 | 00051 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00052 _______________________________________________________________________ 00053 */ 00054 00055 #ifndef _SO_FIELD_ 00056 #define _SO_FIELD_ 00057 00058 #include <Inventor/SbString.h> 00059 #include <Inventor/SoType.h> 00060 #include <Inventor/misc/SoNotification.h> 00061 00062 class SoEngineOutput; 00063 class SoFieldContainer; 00064 struct SoFieldAuditorInfo; 00065 class SoFieldConverter; 00066 class SoFieldList; 00067 class SoInput; 00068 class SoNotList; 00069 class SoOutput; 00070 00071 00074 00183 00184 00185 class INVENTOR_API SoField { 00186 public: 00188 virtual ~SoField(); 00189 00193 void setIgnored(SbBool ig); 00196 SbBool isIgnored() const { return flags.ignored; } 00197 00203 SbBool isDefault() const { return flags.hasDefault; } 00204 00206 static SoType getClassTypeId() { return classTypeId; } 00207 00209 virtual SoType getTypeId() const = 0; 00210 00223 SbBool isOfType(SoType type) const; 00224 00240 void enableConnection(SbBool flag); 00243 SbBool isConnectionEnabled() const 00244 { return flags.connectionEnabled; } 00245 00248 SbBool connectFrom(SoEngineOutput *engineOutput); 00249 SbBool connectFrom(SoField *field); 00250 00253 void disconnect(); 00254 00256 SbBool isConnected() const { return flags.connected; } 00258 SbBool isConnectedFromEngine() const 00259 { return (flags.connected && flags.fromEngine); } 00261 SbBool isConnectedFromField() const 00262 { return (flags.connected && ! flags.fromEngine); } 00263 00268 SbBool getConnectedEngine(SoEngineOutput *&engineOutput) const; 00273 SbBool getConnectedField(SoField *&field) const; 00274 00278 int getForwardConnections(SoFieldList &list) const; 00279 00281 SoFieldContainer * getContainer() const; 00282 00289 SbBool set(const char *valueString); 00290 00293 void get(SbString &valueString); 00294 00301 virtual void touch(); 00302 00305 int operator ==(const SoField &f) const 00306 { return isSame(f); } 00309 int operator !=(const SoField &f) const 00310 { return ! isSame(f); } 00311 00312 SoEXTENDER protected: 00314 SoField(); 00315 00316 SoINTERNAL public: 00317 static void initClass(); 00318 00320 static void initClasses(); 00321 00323 void setDefault(SbBool def) { flags.hasDefault = (def ? 1 : 0 ); } 00324 00326 virtual void startNotify(); 00327 virtual void notify(SoNotList *list); 00328 00331 void setContainer(SoFieldContainer *cont); 00332 00336 SbBool shouldWrite() const; 00337 00339 void addAuditor(void *auditor, SoNotRec::Type type); 00340 void removeAuditor(void *auditor, SoNotRec::Type type); 00341 00345 SbBool enableNotify(SbBool flag); 00346 SbBool isNotifyEnabled() const 00347 { return flags.notifyEnabled; } 00348 00361 SbBool enableContainerNotify(SbBool flag); 00362 SbBool isContainerNotifyEnabled() const 00363 { return flags.notifyContainerEnabled; } 00364 00370 virtual void connectionStatusChanged(int numConnections); 00371 00375 SbBool isReadOnly() const { return flags.readOnly; } 00376 00380 virtual SbBool isSame(const SoField &f) const = 0; 00381 00383 virtual void copyFrom(const SoField &f) = 0; 00384 00389 virtual void fixCopy(SbBool copyConnections); 00390 00397 virtual SbBool referencesCopy() const; 00398 00401 void copyConnection(const SoField *fromField); 00402 00406 virtual SbBool read(SoInput *in, const SbName &name); 00407 00409 virtual void write(SoOutput *out, const SbName &name) const; 00410 00412 virtual void countWriteRefs(SoOutput *out) const; 00413 00418 void evaluate() const 00419 { if (flags.dirty) evaluateConnection(); } 00420 00421 protected: 00425 void valueChanged(SbBool resetDefault = TRUE); 00426 00430 virtual void evaluateConnection() const; 00431 00433 virtual SbBool readValue(SoInput *in) = 0; 00434 00436 virtual SbBool readConnection(SoInput *in); 00437 00439 virtual void writeValue(SoOutput *out) const = 0; 00440 00442 virtual void writeConnection(SoOutput *out) const; 00443 00444 private: 00445 static SoType classTypeId; 00446 00448 static char *fieldBuf; 00449 static int fieldBufSize; 00450 00452 struct { 00453 unsigned int hasDefault : 1; 00454 unsigned int ignored : 1; 00455 unsigned int connected : 1; 00456 unsigned int converted : 1; 00457 unsigned int fromEngine : 1; 00458 unsigned int connectionEnabled : 1; 00459 unsigned int notifyEnabled : 1; 00460 unsigned int hasAuditors : 1; 00461 unsigned int isEngineModifying : 1; 00462 unsigned int readOnly : 1; 00463 00464 unsigned int dirty : 1; 00465 00466 unsigned int notifyContainerEnabled : 1; 00467 } flags; 00468 00474 union { 00475 SoFieldContainer *container; 00476 SoFieldAuditorInfo *auditorInfo; 00477 }; 00478 00480 void createAuditorInfo(); 00481 00484 SoFieldConverter *createConverter(const SoType &fromFieldType) const; 00485 00487 void reallyDisconnect(); 00488 00491 SoFieldConverter * getConverter() const; 00492 00494 void getConnectionInfo(SoFieldContainer *&, SbName&) const; 00495 00498 static void * reallocFieldBuf(void *ptr, size_t newSize); 00499 00500 friend class SoEngineOutput; 00501 }; 00502 00503 00506 00535 00536 00537 class INVENTOR_API SoSField : public SoField { 00538 public: 00540 virtual ~SoSField(); 00541 00543 static SoType getClassTypeId() { return classTypeId; } 00544 00545 protected: 00547 SoSField(); 00548 00549 SoINTERNAL public: 00550 static void initClass(); 00551 00552 static void * createInstance(); 00553 00554 private: 00555 static SoType classTypeId; 00556 00558 virtual SbBool readValue(SoInput *in) = 0; 00559 00561 virtual void writeValue(SoOutput *out) const = 0; 00562 }; 00563 00564 00567 00626 00627 00628 class INVENTOR_API SoMField : public SoField { 00629 00630 public: 00632 virtual ~SoMField(); 00633 00635 int getNum() const { evaluate(); return num; } 00636 00639 void setNum(int num); 00640 00647 virtual void deleteValues(int start, int num = -1); 00648 00653 virtual void insertSpace(int start, int num); 00654 00658 SbBool set1(int index, const char *valueString); 00662 void get1(int index, SbString &valueString); 00663 00665 static SoType getClassTypeId() { return classTypeId; } 00666 00667 SoINTERNAL public: 00668 static void initClass(); 00669 00670 static void * createInstance(); 00671 00672 protected: 00673 int num; 00674 int maxNum; 00675 00677 SoMField(); 00678 00680 virtual void makeRoom(int newNum); 00681 00682 private: 00683 static SoType classTypeId; 00684 00686 static char *fieldBuf; 00687 static int fieldBufSize; 00688 00691 virtual void allocValues(int num) = 0; 00692 00694 virtual void deleteAllValues() = 0; 00695 00697 virtual void copyValue(int to, int from) = 0; 00698 00700 virtual SbBool readValue(SoInput *in); 00701 00703 virtual SbBool read1Value(SoInput *in, int index) = 0; 00704 00706 virtual void writeValue(SoOutput *out) const; 00707 00709 virtual void write1Value(SoOutput *out, int index) const = 0; 00710 00712 virtual SbBool readBinaryValues(SoInput *in, int numToRead); 00713 00715 virtual void writeBinaryValues(SoOutput *out) const; 00716 00718 virtual int getNumValuesPerLine() const; 00719 00722 static void * reallocFieldBuf(void *ptr, size_t newSize); 00723 }; 00724 00725 #endif /* _SO_FIELD_ */