1 // Created: Tue Nov 2 14:40:06 1999
2 // Author: Andrey BETENEV
3 // Copyright (c) 1999-2020 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Express_Entity.hxx>
18 #include <Express.hxx>
19 #include <Express_Alias.hxx>
20 #include <Express_Boolean.hxx>
21 #include <Express_ComplexType.hxx>
22 #include <Express_Enum.hxx>
23 #include <Express_Field.hxx>
24 #include <Express_HSequenceOfEntity.hxx>
25 #include <Express_HSequenceOfField.hxx>
26 #include <Express_Integer.hxx>
27 #include <Express_Logical.hxx>
28 #include <Express_NamedType.hxx>
29 #include <Express_Number.hxx>
30 #include <Express_Real.hxx>
31 #include <Express_Select.hxx>
32 #include <Express_String.hxx>
33 #include <Express_Type.hxx>
34 #include <Message.hxx>
35 #include <OSD_Directory.hxx>
36 #include <OSD_FileSystem.hxx>
37 #include <OSD_Path.hxx>
38 #include <OSD_Protection.hxx>
40 IMPLEMENT_STANDARD_RTTIEXT(Express_Entity, Express_Item)
42 //=======================================================================
43 // function : Express_Entity
45 //=======================================================================
47 Express_Entity::Express_Entity (const Standard_CString theName,
48 const Handle(TColStd_HSequenceOfHAsciiString)& theInherit,
49 const Handle(Express_HSequenceOfField)& theFields)
50 : Express_Item (theName), mySupers (theInherit), myFields (theFields)
52 // make empty lists to avoid checking every time
53 myInherit = new Express_HSequenceOfEntity;
54 if (mySupers.IsNull())
56 mySupers = new TColStd_HSequenceOfHAsciiString;
58 if (myFields.IsNull())
60 myFields = new Express_HSequenceOfField;
62 myIsAbstract = Standard_False;
65 //=======================================================================
66 // function : SuperTypes
68 //=======================================================================
70 const Handle(TColStd_HSequenceOfHAsciiString)& Express_Entity::SuperTypes() const
75 //=======================================================================
78 //=======================================================================
80 const Handle(Express_HSequenceOfEntity)& Express_Entity::Inherit() const
85 //=======================================================================
88 //=======================================================================
90 const Handle(Express_HSequenceOfField)& Express_Entity::Fields() const
94 //=======================================================================
95 // function : NbFields
97 //=======================================================================
99 Standard_Integer Express_Entity::NbFields (const Standard_Boolean theInherited) const
101 Standard_Integer aNb = myFields->Length();
104 for (Standard_Integer i = 1; i <= myInherit->Length(); i++)
106 aNb += myInherit->Value (i)->NbFields (theInherited);
112 //=======================================================================
113 // function : WriteGetMethod
115 //=======================================================================
117 static void writeGetMethod (
118 Standard_OStream& theOS,
119 const TCollection_AsciiString& theName,
120 const TCollection_AsciiString& theField,
121 const TCollection_AsciiString& theType,
122 const Standard_Boolean isHandle,
123 const Standard_Boolean /*isSimple*/)
125 const TCollection_AsciiString& aMethod = theField;
126 Express::WriteMethodStamp (theOS, aMethod);
127 theOS << (isHandle ? "Handle(" : "") << theType << (isHandle ? ") " : " ") << theName << "::" << aMethod << "() const\n"
129 " return my" << theField << ";\n"
133 //=======================================================================
134 // function : WriteSetMethod
136 //=======================================================================
138 static void writeSetMethod (
139 Standard_OStream& theOS,
140 const TCollection_AsciiString& theName,
141 const TCollection_AsciiString& theField,
142 const TCollection_AsciiString& theType,
143 const Standard_Boolean isHandle,
144 const Standard_Boolean isSimple)
146 TCollection_AsciiString aMethod = "Set";
148 Express::WriteMethodStamp (theOS, aMethod);
149 theOS << "void " << theName << "::" << aMethod << " (const " << (isHandle ? "Handle(" : "") << theType << (isHandle ? ")" : "") <<
150 (isSimple ? "" : "&") << " the" << theField << ")\n"
152 " my" << theField << " = the" << theField << ";\n"
156 //=======================================================================
157 // function : WriteSpaces
159 //=======================================================================
161 static inline void writeSpaces (Standard_OStream& theOS, Standard_Integer theNum)
163 for (Standard_Integer i = 0; i < theNum; i++)
167 //=======================================================================
168 // function : GenerateClass
170 //=======================================================================
172 Standard_Boolean Express_Entity::GenerateClass() const
174 const TCollection_AsciiString aCPPName = CPPName();
175 Message::SendInfo() << "Generating ENTITY " << aCPPName;
177 // create a package directory (if not yet exist)
178 OSD_Protection aProt (OSD_RWXD, OSD_RWXD, OSD_RX, OSD_RX);
179 TCollection_AsciiString aPack = GetPackageName();
180 OSD_Path aPath (aPack);
181 OSD_Directory aDir (aPath);
185 const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
187 //===============================
188 // Step 1: generating HXX
189 TCollection_AsciiString anInheritName;
192 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".hxx"), std::ios::out | std::ios::binary);
193 Standard_OStream& anOS = *aStreamPtr;
196 Express::WriteFileStamp (anOS);
198 // write include protection and "standard" includes
199 anOS << "#ifndef _" << aCPPName << "_HeaderFile_\n"
200 "#define _" << aCPPName << "_HeaderFile_\n"
202 "#include <Standard.hxx>\n"
203 "#include <Standard_Type.hxx>\n";
204 if (myInherit->Length() < 1)
206 anInheritName = "Standard_Transient";
207 anOS << "#include <" << anInheritName << ".hxx>\n";
211 // first inherited class will be actually inherited
212 Handle(Express_Entity) anEntity = myInherit->Value (1);
213 anInheritName = anEntity->CPPName();
214 // make warning if there are more than one inherits
215 if (myInherit->Length() > 1)
217 Message::SendWarning() << "Warning: ENTITY " << Name() << " defined with multiple inheritance;";
218 Message::SendWarning() << "Warning: only first base class " << anInheritName << " is actually inherited, others are made fields";
221 // write other includes (inherits and used types)
222 writeIncludes (anOS);
224 // write HANDLE MACRO
226 "DEFINE_STANDARD_HANDLE(" << aCPPName << ", " << anInheritName << ")\n"
229 // write start of declaration (inheritance)
230 anOS << "//! Representation of STEP entity " << Name() << "\n"
231 "class " << aCPPName << " : public " << anInheritName << "\n"
238 anOS << " //! default constructor\n"
239 " Standard_EXPORT " << aCPPName << "();\n"
242 // write Init methods
243 if (myInherit->Length() > 1 || myFields->Length() > 0)
245 anOS << " //! Initialize all fields (own and inherited)\n"
246 " Standard_EXPORT void Init (";
247 makeInit (anOS, 29, Standard_True, 0);
252 // write methods Get/Set
253 for (Standard_Integer i = 2; i <= myInherit->Length(); i++)
255 Handle(Express_Entity) anEntity = myInherit->Value (i);
256 const TCollection_AsciiString& aName = anEntity->Name();
257 const TCollection_AsciiString& anEntityCPPName = anEntity->CPPName();
258 anOS << " //! Returns data for supertype " << aName << "\n"
259 " Standard_EXPORT Handle(" << anEntityCPPName << ") " << aName << "() const;\n"
260 " //! Sets data for supertype " << aName << "\n"
261 " Standard_EXPORT void Set" << aName << " (const Handle(" << anEntityCPPName << ")& the" << aName << ");\n"
264 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
266 Handle(Express_Field) aField = myFields->Value (i);
267 Handle(Express_Type) aFieldType = aField->Type();
268 TCollection_AsciiString aFieldCPPName = aFieldType->CPPName();
269 anOS << " //! Returns field " << aField->Name() << "\n";
270 if (aFieldType->IsHandle())
272 anOS << " Standard_EXPORT Handle(" << aFieldCPPName << ") " << aField->Name() << "() const;\n";
276 anOS << " Standard_EXPORT " << aFieldCPPName << " " << aField->Name() << "() const;\n";
279 " //! Sets field " << aField->Name() << "\n";
280 if (aFieldType->IsHandle())
282 anOS << " Standard_EXPORT void Set" << aField->Name() << " (const Handle("
283 << aFieldCPPName << ")& the" << aField->Name() << ");\n";
287 anOS << " Standard_EXPORT void Set" << aField->Name() << " (const "
288 << aFieldCPPName << (aFieldType->IsSimple() ? "" : "&")
289 << " the" << aField->Name() << ");\n";
291 if (aField->IsOptional())
294 " //! Returns True if optional field " << aField->Name() << " is defined\n"
295 " Standard_EXPORT Standard_Boolean Has" << aField->Name() << "() const;\n";
299 // prepare additional methods for HArray1 field (NbField() and <field_elem> FieldValue(int num))
300 Standard_Integer aFindPos = aFieldCPPName.Search ("_HArray");
303 TCollection_AsciiString aNamePack = aFieldCPPName.SubString (1, aFindPos);
304 TCollection_AsciiString aNameClass;
305 if (aNamePack.IsEqual ("TColStd_"))
307 Standard_Integer aFindPos2 = aFieldCPPName.Search ("Integer");
310 aNameClass = "Standard_Integer";
314 aFindPos2 = aFieldCPPName.Search ("Real");
317 aNameClass = "Standard_Real";
321 aNameClass = "Standard_Boolean";
327 if (aNamePack.IsEqual ("Interface_"))
329 aNameClass = "Handle(TCollection_HAsciiString)";
333 aNameClass = "Handle(";
334 aNameClass += aNamePack;
335 aNameClass += aFieldCPPName.SubString (aFindPos + 10, aFieldCPPName.Length());
339 anOS << " //! Returns number of " << aField->Name() << "\n"
340 " Standard_EXPORT Standard_Integer Nb" << aField->Name() << "() const;\n"
342 " //! Returns value of " << aField->Name() << " by its num\n"
343 " Standard_EXPORT " << aNameClass << " " << aField->Name() << "Value (const Standard_Integer theNum) const;\n"
348 anOS << " DEFINE_STANDARD_RTTIEXT(" << aCPPName << ", " << anInheritName << ")\n"
351 // write fields section
352 if (myInherit->Length() > 1 || myFields->Length() > 0)
356 for (Standard_Integer i = 2; i <= myInherit->Length(); i++)
358 Handle(Express_Entity) anEntity = myInherit->Value (i);
359 anOS << " Handle(" << anEntity->CPPName() << ") my" << anEntity->Name() << "; //!< supertype\n";
361 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
363 Handle(Express_Field) aField = myFields->Value (i);
364 Handle(Express_Type) aFieldType = aField->Type();
365 if (aFieldType->IsHandle())
367 anOS << " Handle(" << aFieldType->CPPName() << ") my" << aField->Name() << ";";
371 anOS << " " << aFieldType->CPPName() << " my" << aField->Name() << ";";
373 if (aField->IsOptional())
375 anOS << " //!< optional";
379 // optional fields: flag 'is field set'
380 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
382 Handle(Express_Field) aField = myFields->Value (i);
383 if (!aField->IsOptional())
387 anOS << " Standard_Boolean myHas" << aField->Name() << "; //!< flag \"is "
388 << aField->Name() << " defined\"\n";
396 "#endif // _" << aCPPName << "_HeaderFile_\n";
399 //===============================
400 // Step 2: generating CXX
403 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".cxx"), std::ios::out | std::ios::binary);
404 Standard_OStream& anOS = *aStreamPtr;
407 Express::WriteFileStamp (anOS);
409 // write include section
410 anOS << "#include <" << aCPPName << ".hxx>\n"
412 "IMPLEMENT_STANDARD_RTTIEXT(" << aCPPName << ", " << anInheritName << ")\n";
415 Express::WriteMethodStamp (anOS, aCPPName);
416 anOS << aCPPName << "::" << aCPPName << "()\n"
418 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
420 Handle(Express_Field) aField = myFields->Value (i);
421 if (aField->IsOptional())
422 anOS << " myHas" << aField->Name() << " = Standard_False;\n";
426 // write method Init()
427 if (myInherit->Length() > 1 || myFields->Length() > 0)
429 Express::WriteMethodStamp (anOS, "Init");
430 anOS << "void " << aCPPName << "::Init (";
431 makeInit (anOS, 13 + aCPPName.Length(), Standard_True, 1);
434 makeInit (anOS, -2, Standard_True, 3);
439 // write "methods" section
440 for (Standard_Integer i = 2; i <= myInherit->Length(); i++)
442 Handle(Express_Entity) anEntity = myInherit->Value (i);
443 const TCollection_AsciiString& anEntityCPPName = anEntity->CPPName();
444 writeGetMethod (anOS, aCPPName, anEntity->Name(), anEntityCPPName, Standard_True, Standard_False);
445 writeSetMethod (anOS, aCPPName, anEntity->Name(), anEntityCPPName, Standard_True, Standard_False);
447 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
449 Handle(Express_Field) aField = myFields->Value (i);
450 Handle(Express_Type) aFieldType = aField->Type();
451 TCollection_AsciiString aFieldCPPName = aFieldType->CPPName();
452 writeGetMethod (anOS, aCPPName, aField->Name(), aFieldCPPName, aFieldType->IsHandle(), aFieldType->IsSimple());
453 writeSetMethod (anOS, aCPPName, aField->Name(), aFieldCPPName, aFieldType->IsHandle(), aFieldType->IsSimple());
454 if (aField->IsOptional())
456 TCollection_AsciiString aMethod = "Has";
457 aMethod += aField->Name();
458 Express::WriteMethodStamp (anOS, aMethod);
459 anOS << "Standard_Boolean " << aCPPName << "::" << aMethod << "() const\n"
461 " return myHas" << aField->Name() << ";\n"
465 // prepare additional methods for HArray1 field
466 Standard_Integer aFindPos = aFieldCPPName.Search ("_HArray1");
469 TCollection_AsciiString aNamePack = aFieldCPPName.SubString (1, aFindPos);
470 TCollection_AsciiString aNameClass ("");
471 if (aNamePack.IsEqual ("TColStd_"))
473 Standard_Integer aFindPos2 = aFieldCPPName.Search ("Integer");
476 aNameClass = "Standard_Integer";
480 aFindPos2 = aFieldCPPName.Search ("Real");
483 aNameClass = "Standard_Real";
487 aNameClass = "Standard_Boolean";
493 if (aNamePack.IsEqual ("Interface_"))
495 aNameClass = "Handle(TCollection_HAsciiString)";
499 aNameClass = "Handle(";
500 aNameClass += aNamePack;
501 aNameClass += aFieldCPPName.SubString (aFindPos + 10, aFieldCPPName.Length());
505 // write method ::NbField()
507 TCollection_AsciiString aMethodName = "Nb";
508 aMethodName += aField->Name();
509 Express::WriteMethodStamp (anOS, aMethodName);
510 anOS << "Standard_Integer " << aCPPName << "::Nb" << aField->Name() << "() const;\n"
512 " if (my" << aField->Name() << ".IsNull())\n"
516 " return my" << aField->Name() << "->Length();\n"
518 // write method ::FieldValue(num)
520 aMethodName = aField->Name();
521 aMethodName += "Value";
522 Express::WriteMethodStamp (anOS, aMethodName);
523 anOS << aNameClass << " " << aCPPName << "::" << aField->Name() << "Value (const Standard_Integer theNum) const;\n"
525 " return my" << aField->Name() << "->Value (theNum);\n"
535 // generation of RW class is not needed
536 return Standard_True;
539 //===============================
540 // Step 3: generating HXX for Reader/Writer class
541 TCollection_AsciiString aRWCPPName;
545 aRWCPPName += GetPackageName();
547 aRWCPPName += Name();
550 aPack += GetPackageName();
551 OSD_Path aRWPath (aPack);
552 OSD_Directory aRWDir (aRWPath);
553 aRWDir.Build (aProt);
557 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".hxx"), std::ios::out | std::ios::binary);
558 Standard_OStream& anOS = *aStreamPtr;
561 Express::WriteFileStamp (anOS);
563 anOS << "#ifndef _" << aRWCPPName << "_HeaderFile_\n"
564 "#define _" << aRWCPPName << "_HeaderFile_\n"
568 anOS << "#include <Standard.hxx>\n"
569 "#include <Standard_DefineAlloc.hxx>\n"
570 "#include <Standard_Handle.hxx>\n"
572 "class StepData_StepReaderData;\n"
573 "class Interface_Check;\n"
574 "class StepData_StepWriter;\n"
575 "class Interface_EntityIterator;\n"
576 "class " << aCPPName << ";\n"
579 // write start of declaration (inheritance)
580 anOS << "//! Read & Write tool for " << Name() << "\n"
581 "class " << aRWCPPName << "\n"
586 " DEFINE_STANDARD_ALLOC\n"
589 // default constructor
590 anOS << " Standard_EXPORT " << aRWCPPName << "();\n"
594 anOS << " Standard_EXPORT void ReadStep (const Handle(StepData_StepReaderData)& theData,\n"
595 " const Standard_Integer theNum,\n"
596 " Handle(Interface_Check)& theCheck,\n"
597 " const Handle(" << aCPPName << ")& theEnt) const;\n"
601 anOS << " Standard_EXPORT void WriteStep (StepData_StepWriter& theSW,\n"
602 " const Handle(" << aCPPName << ")& theEnt) const;\n"
606 anOS << " Standard_EXPORT void Share (const Handle(" << aCPPName << ")& theEnt,\n"
607 " Interface_EntityIterator& theIter) const;\n"
613 "#endif // _" << aRWCPPName << "_HeaderFile_\n";
616 //===============================
617 // Step 4: generating CXX for Read/Write tool
620 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".cxx"), std::ios::out | std::ios::binary);
621 Standard_OStream& anOS = *aStreamPtr;
624 Express::WriteFileStamp (anOS);
626 // write include section
627 anOS << "#include <" << aRWCPPName << ".hxx>\n";
628 anOS << "#include <" << aCPPName << ".hxx>\n";
629 anOS << "#include <Interface_EntityIterator.hxx>\n"
630 "#include <StepData_StepReaderData.hxx>\n"
631 "#include <StepData_StepWriter.hxx>\n";
633 Express::WriteMethodStamp (anOS, aRWCPPName);
634 anOS << aRWCPPName << "::" << aRWCPPName << "() {}\n"
637 // write method ReadStep
638 Express::WriteMethodStamp (anOS, "ReadStep");
639 if (aRWCPPName.Length() < 40)
641 anOS << "void " << aRWCPPName << "::ReadStep (const Handle(StepData_StepReaderData)& theData,\n";
642 writeSpaces (anOS, 17 + aRWCPPName.Length());
643 anOS << "const Standard_Integer theNum,\n";
644 writeSpaces (anOS, 17 + aRWCPPName.Length());
645 anOS << "Handle(Interface_Check)& theCheck,\n";
646 writeSpaces (anOS, 17 + aRWCPPName.Length());
647 anOS << "const Handle(" << aCPPName << ")& theEnt) const\n";
651 anOS << "void " << aRWCPPName << "::ReadStep (\n"
652 " const Handle(StepData_StepReaderData)& theData,\n"
653 " const Standard_Integer theNum,\n"
654 " Handle(Interface_Check)& theCheck,\n"
655 " const Handle(" << aCPPName << ")& theEnt) const\n";
658 Standard_Integer aNbFields = NbFields (Standard_True);
660 anOS << " // Check number of parameters\n"
661 " if (!theData->CheckNbParams (theNum, " << aNbFields << ", theCheck, \"" << Express::ToStepName (Name()) << "\"))\n"
665 writeRWReadCode (anOS, 1, Standard_True); // write code for reading inherited and own fields
667 " // Initialize entity\n"
669 makeInit (anOS, 15, Standard_True, 4);
673 // write method WriteStep
674 Express::WriteMethodStamp (anOS, "WriteStep");
675 if (aRWCPPName.Length() < 40)
677 anOS << "void " << aRWCPPName << "::WriteStep (StepData_StepWriter& theSW,\n";
678 writeSpaces (anOS, 18 + aRWCPPName.Length());
679 anOS << "const Handle(" << aCPPName << ")& theEnt) const\n";
683 anOS << "void " << aRWCPPName << "::WriteStep (\n"
684 " StepData_StepWriter& theSW,\n"
685 " const Handle(" << aCPPName << ")& theEnt) const\n";
689 writeRWWriteCode (anOS, 0, Standard_True); // write code for writing inherited and own fields
692 // write method Share
693 Express::WriteMethodStamp (anOS, "Share");
694 std::ostringstream aStringOS;
695 Standard_Integer aNnFileds2 = writeRWShareCode (aStringOS, 1, Standard_True); // write code for filling graph of references
696 if (aRWCPPName.Length() < 40)
698 anOS << "void " << aRWCPPName << "::Share (const Handle(" << aCPPName << ")&" << ((aNnFileds2 > 1) ? "theEnt," : ",") << "\n";
699 writeSpaces (anOS, 14 + aRWCPPName.Length());
702 anOS << "Interface_EntityIterator& theIter) const\n";
706 anOS << "Interface_EntityIterator&) const\n";
711 anOS << "void " << aRWCPPName << "::Share(\n"
712 " const Handle(" << aCPPName << ")&" << ((aNnFileds2 > 1) ? "theEnt," : ",") << "\n";
715 anOS << "Interface_EntityIterator& theIter) const\n";
719 anOS << "Interface_EntityIterator&) const\n";
725 anOS << aStringOS.str();
730 Express::WriteMethodStamp (anOS, "Check");
731 anOS << "void " << aRWCPPName << "::Check (const Handle(Standard_Transient)& entt,\n";
732 writeSpaces (anOS, 18 + aRWCPPName.Length());
733 anOS << "const Interface_ShareTool& shares,\n";
734 writeSpaces (anOS, 18 + aRWCPPName.Length());
735 anOS << "Interface_Check& check) const\n"
737 // DownCast entity to it's type
738 anOS << " Handle(" << aCPPName << ") ent = Handle(" << aCPPName << ")::DownCast(entt);\n"
741 if (FillSharedFlag())
743 Express::WriteMethodStamp (anOS, "FillShared");
744 anOS << "void " << aRWCPPName << "::Share(const Handle(Interface_InterfaceModel)& model,\n";
745 writeSpaces (anOS, 18 + aRWCPPName.Length());
746 anOS << "const Handle(Standard_Transient)& entt,\n";
747 writeSpaces (anOS, 18 + aRWCPPName.Length());
748 anOS << "Interface_EntityIterator& iter) const\n"
750 // DownCast entity to it's type
751 anOS << " Handle(" << aCPPName << ") ent = Handle(" << aCPPName << ")::DownCast(entt)\n"
758 //===============================
759 // Step 5: adding method for registration of entities and include
761 Standard_Integer anIndex = Express_Item::Index();
762 TCollection_AsciiString aRegDir = "Registration";
763 OSD_Path aPathReg (aRegDir);
764 OSD_Directory aDirReg (aRegDir);
765 aDirReg.Build (aProt);
768 // write file with includes
770 TCollection_AsciiString aPackNameInc = "inc.txt";
771 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameInc), std::ios::out | std::ios::binary | std::ios::app);
772 Standard_OStream& anOS = *aStreamPtr;
773 anOS << "#include <" << aCPPName << ".hxx>\n";
776 // write file with RW includes
778 TCollection_AsciiString aPackNameRWInc = "rwinc.txt";
779 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameRWInc), std::ios::out | std::ios::binary | std::ios::app);
780 Standard_OStream& anOS = *aStreamPtr;
781 anOS << "#include <" << aRWCPPName << ".hxx>\n";
785 // generate data for entity registration
788 // StepAP214_Protocol.cxx
790 TCollection_AsciiString aPackNameProtocol = "protocol.txt";
791 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameProtocol), std::ios::out | std::ios::binary | std::ios::app);
792 Standard_OStream& anOS = *aStreamPtr;
793 anOS << "types.Bind (STANDARD_TYPE(" << aCPPName << "), " << anIndex << ");\n";
796 // RWStepAP214_GeneralModule.cxx
799 TCollection_AsciiString aPackNameFillShared = "fillshared.txt";
800 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameFillShared), std::ios::out | std::ios::binary | std::ios::app);
801 Standard_OStream& anOS = *aStreamPtr;
802 anOS << " case " << anIndex << ":\n"
804 " DeclareAndCast (" << aCPPName << ", anent, ent);\n"
805 " " << aRWCPPName << " aTool;\n"
806 " aTool.Share(anent, iter);\n"
813 TCollection_AsciiString aPackNameNewVoid = "newvoid.txt";
814 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameNewVoid), std::ios::out | std::ios::binary | std::ios::app);
815 Standard_OStream& anOS = *aStreamPtr;
816 anOS << " case " << anIndex << ":\n"
817 " ent = new " << aCPPName << ";\n"
823 TCollection_AsciiString aPackNameCategory = "category.txt";
824 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameCategory), std::ios::out | std::ios::binary | std::ios::app);
825 Standard_OStream& anOS = *aStreamPtr;
826 anOS << " case " << anIndex << ": return " << Category() << ";\n";
829 // RWStepAP214_ReadWriteModule.cxx
832 TCollection_AsciiString aRecoName = Express::ToStepName (Name());
833 aRecoName.UpperCase();
834 TCollection_AsciiString aPackNameReco = "reco.txt";
835 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameReco), std::ios::out | std::ios::binary | std::ios::app);
836 Standard_OStream& anOS = *aStreamPtr;
837 anOS << " static TCollection_AsciiString Reco_" << Name() << " (\"" << aRecoName << "\");\n";
842 TCollection_AsciiString aPackNameTypeBind = "typebind.txt";
843 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameTypeBind), std::ios::out | std::ios::binary | std::ios::app);
844 Standard_OStream& anOS = *aStreamPtr;
845 anOS << " typenums.Bind (Reco_" << Name() << ", " << anIndex << ");\n";
850 TCollection_AsciiString aPackNameStepType = "steptype.txt";
851 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameStepType), std::ios::out | std::ios::binary | std::ios::app);
852 Standard_OStream& anOS = *aStreamPtr;
853 anOS << " case " << anIndex << ": return Reco_" << Name() << ";\n";
858 TCollection_AsciiString aPackNameReadStep = "readstep.txt";
859 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameReadStep), std::ios::out | std::ios::binary | std::ios::app);
860 Standard_OStream& anOS = *aStreamPtr;
861 anOS << " case " << anIndex << ":\n"
863 " DeclareAndCast (" << aCPPName << ", anent, ent);\n"
864 " " << aRWCPPName << " aTool;\n"
865 " aTool.ReadStep (data, num, ach, anent);\n"
872 TCollection_AsciiString aPackNameWriteStep = "writestep.txt";
873 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aRegDir.Cat (aPackNameWriteStep), std::ios::out | std::ios::binary | std::ios::app);
874 Standard_OStream& anOS = *aStreamPtr;
875 anOS << " case " << anIndex << ":\n"
877 " DeclareAndCast (" << aCPPName << ", anent, ent);\n"
878 " " << aRWCPPName << " aTool;\n"
879 " aTool.WriteStep (SW, anent);\n"
884 Express_Item::SetIndex (anIndex + 1);
887 return Standard_True;
890 //=======================================================================
891 // function : PropagateUse
893 //=======================================================================
895 void Express_Entity::PropagateUse() const
897 const TCollection_AsciiString& aPack = GetPackageName();
898 const TCollection_AsciiString& aName = Name();
900 for (Standard_Integer i = 1; i <= myInherit->Length(); i++)
902 Handle(Express_Entity) anEntity = myInherit->Value (i);
903 anEntity->Use2 (aName, aPack);
905 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
907 Handle(Express_Type) aType = myFields->Value (i)->Type();
908 aType->Use2 (aName, aPack);
912 //=======================================================================
913 // function : WriteIncludes
915 //=======================================================================
917 Standard_Boolean Express_Entity::writeIncludes (Standard_OStream& theOS) const
919 DataMapOfStringInteger aDict;
921 for (Standard_Integer i = 1; i <= myInherit->Length(); i++)
923 Handle(Express_Entity) anEntity = myInherit->Value (i);
925 const TCollection_AsciiString& anEntityCPPName = anEntity->CPPName();
926 if (aDict.IsBound (anEntityCPPName))
928 continue; // avoid duplicating
930 aDict.Bind (anEntityCPPName, 1);
931 theOS << "#include <" << anEntityCPPName << ".hxx>\n";
933 // write includes for own fields
934 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
936 Handle(Express_Type) aType = myFields->Value (i)->Type();
938 const TCollection_AsciiString aTypeCPPName = aType->CPPName();
939 if (aDict.IsBound (aTypeCPPName))
941 continue; // avoid duplicating
943 aDict.Bind (aTypeCPPName, 1);
944 if (aType->IsStandard())
948 theOS << "#include <" << aTypeCPPName << ".hxx>\n";
949 const TCollection_AsciiString& aPack = GetPackageName();
950 // check that last include is for array
951 TCollection_AsciiString aStrForSearch = aPack;
952 aStrForSearch += "_HArray";
953 Standard_Integer aFindPos = aTypeCPPName.Search (aStrForSearch.ToCString());
956 // prepare file names
957 aFindPos = aPack.Length();
958 const TCollection_AsciiString& aNameHA = aTypeCPPName;
959 TCollection_AsciiString aNameA = aNameHA.SubString (1, aFindPos + 1);
960 aNameA += aNameHA.SubString (aFindPos + 3, aNameHA.Length());
961 TCollection_AsciiString aNameClass = aNameHA.SubString (aFindPos + 11, aNameHA.Length());
962 const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
963 // create a package directory (if not yet exist)
964 OSD_Protection aProt (OSD_RWXD, OSD_RWXD, OSD_RX, OSD_RX);
965 OSD_Path aPath (aPack);
966 OSD_Directory aDir (aPath);
968 // create hxx files for Array1
971 TCollection_AsciiString aFileName = aPack;
974 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aFileName.Cat (".hxx"), std::ios::out | std::ios::binary);
975 Standard_OStream& anOS = *aStreamPtr;
977 Express::WriteFileStamp (anOS);
979 "#ifndef " << aNameA << "_HeaderFile\n"
980 "#define " << aNameA << "_HeaderFile\n"
982 "#include <" << aPack << "_" << aNameClass << ".hxx>\n"
983 "#include <NCollection_" << aNameHA.SubString (aFindPos + 3, aFindPos + 8) << ".hxx>\n"
985 "typedef NCollection_" << aNameHA.SubString (aFindPos + 3, aFindPos + 8) << "<Handle(" << aPack << "_" << aNameClass << ")> " << aNameA << ";\n"
990 // create hxx files for HArray1
993 TCollection_AsciiString aFileName = aPack;
995 aFileName += aNameHA;
996 std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aFileName.Cat (".hxx"), std::ios::out | std::ios::binary);
997 Standard_OStream& anOS = *aStreamPtr;
999 Express::WriteFileStamp (anOS);
1001 "#ifndef " << aNameHA << "_HeaderFile\n"
1002 "#define " << aNameHA << "_HeaderFile\n"
1004 "#include <" << aNameA << ".hxx>\n"
1005 "#include <NCollection_" << aNameHA.SubString (aFindPos + 2, aFindPos + 8) << ".hxx>\n"
1007 "DEFINE_HARRAY" << aNameHA.SubString (aFindPos + 8, aFindPos + 8) << "(" << aNameHA << ", " << aNameA << ");\n"
1015 return Standard_True;
1018 //=======================================================================
1019 // function : typeToSTEPName
1020 // purpose : auxiliary for WriteRWReadField
1021 //=======================================================================
1023 static TCollection_AsciiString typeToSTEPName (const Handle(Express_Type)& theType)
1025 TCollection_AsciiString aCPPName = theType->CPPName();
1026 TCollection_AsciiString aCls = aCPPName.Token ("_", 2);
1027 if (aCls.Length() < 1)
1031 return Express::ToStepName (aCls);
1034 //=======================================================================
1035 // function : WriteRWReadField
1037 //=======================================================================
1039 static void writeRWReadField (Standard_OStream& theOS,
1040 const TCollection_AsciiString& theIndex,
1041 const TCollection_AsciiString& theSTEPName,
1042 const TCollection_AsciiString& theVarName,
1043 const Handle(Express_Type)& theVarType,
1044 const Standard_Integer theLevel,
1045 const Standard_Boolean isOptional)
1048 TCollection_AsciiString anIdent (" ");
1049 Standard_Integer aLevel = 0;
1050 for (; aLevel < theLevel; aLevel++)
1056 // name of variable identifying number of parameter in data
1057 TCollection_AsciiString aParam ("theNum");
1060 aParam = TCollection_AsciiString ("aNum");
1061 aParam += TCollection_AsciiString (theLevel);
1064 // decode aliased types
1065 Handle(Express_Type) aType = theVarType;
1066 const TCollection_AsciiString aTypeCPPName = aType->CPPName();
1067 while (aType->IsKind (STANDARD_TYPE(Express_NamedType)))
1069 Handle(Express_NamedType) aNamedType = Handle(Express_NamedType)::DownCast (aType);
1070 if (!aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Alias)))
1074 Handle(Express_Alias) anAlias = Handle(Express_Alias)::DownCast (aNamedType->Item());
1075 aType = anAlias->Type();
1079 if (aType->IsHandle())
1081 theOS << anIdent << "Handle(" << aTypeCPPName << ") a";
1085 theOS << anIdent << aTypeCPPName << " a";
1087 theOS << theVarName << ";\n";
1091 theOS << anIdent << "Standard_Boolean has" << theVarName << " = Standard_True;\n" <<
1092 anIdent << "if (theData->IsParamDefined (" << aParam << ", " << theIndex << "))\n" <<
1098 // read variable depending on its type
1099 if (aType->IsKind (STANDARD_TYPE(Express_NamedType)))
1101 Handle(Express_NamedType) aNamedType = Handle(Express_NamedType)::DownCast (aType);
1102 if (aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Entity)))
1104 theOS << anIdent << "theData->ReadEntity (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck,\n" <<
1105 anIdent << " STANDARD_TYPE(" << aNamedType->CPPName() << "), a" << theVarName << ");\n";
1107 else if (aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Select)))
1109 theOS << anIdent << "theData->ReadEntity (" << aParam << ", " << theIndex << ", \"" << theSTEPName <<
1110 "\", theCheck, a" << theVarName << ");\n";
1112 else if (aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Enum)))
1114 theOS << anIdent << "if (theData->ParamType(" << aParam << ", " << theIndex << ") == Interface_ParamEnum)\n" <<
1116 anIdent << " Standard_CString text = theData->ParamCValue(" << aParam << ", " << theIndex << ");\n";
1117 Handle(Express_Enum) anEnum = Handle(Express_Enum)::DownCast (aNamedType->Item());
1118 TCollection_AsciiString aPrefix = Express::EnumPrefix (anEnum->Name());
1119 Handle(TColStd_HSequenceOfHAsciiString) aNames = anEnum->Names();
1120 TCollection_AsciiString anEnumPack = anEnum->GetPackageName();
1121 for (Standard_Integer i = 1; i <= aNames->Length(); i++)
1123 TCollection_AsciiString anEnumName = Express::ToStepName (aNames->Value (i)->String());
1124 anEnumName.UpperCase();
1125 theOS << anIdent << (i == 1 ? " if " : " else if") << " (strcmp (text, \"." << anEnumName << ".\")) a" <<
1126 theVarName << " = " << anEnumPack << "_" << aPrefix << aNames->Value (i)->String() << ";\n";
1128 theOS << anIdent << " else\n" <<
1129 anIdent << " {\n" <<
1130 anIdent << " theCheck->AddFail (\"Parameter #" << theIndex << " (" << theSTEPName << ") has not allowed value\");\n" <<
1131 anIdent << " }\n" <<
1133 anIdent << "else\n" <<
1135 anIdent << " theCheck->AddFail (\"Parameter #" << theIndex << " (" << theSTEPName << ") is not enumeration\");\n" <<
1139 else if (aType->IsKind (STANDARD_TYPE(Express_ComplexType)))
1141 Handle(Express_ComplexType) aComplex = Handle(Express_ComplexType)::DownCast (aType);
1142 theOS << anIdent << "Standard_Integer aSub" << theIndex << " = 0;\n" <<
1143 anIdent << "if (theData->ReadSubList (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck, aSub" << theIndex << "))\n" <<
1145 anIdent << " Standard_Integer aNb" << theLevel << " = theData->NbParams (aSub" << theIndex << ");\n";
1146 TCollection_AsciiString anIterI = theLevel;
1147 anIterI.Prepend ("i");
1148 TCollection_AsciiString aVar = theLevel;
1149 aVar.Prepend ("nIt");
1150 if (aComplex->Type()->IsKind (STANDARD_TYPE(Express_ComplexType)))
1153 Handle(Express_ComplexType) aComplex2 = Handle(Express_ComplexType)::DownCast (aComplex->Type());
1154 TCollection_AsciiString anIterJ = theLevel;
1155 anIterJ.Prepend ("j");
1156 theOS << anIdent << " Standard_Integer nbj" << theLevel << " = theData->NbParams (theData->ParamNumber (aSub" << theIndex << ", 1));\n" <<
1157 anIdent << " a" << theVarName << " = new " << aTypeCPPName << "(1, aNb" << theLevel << ", 1, nbj" << theLevel << ");\n" <<
1158 anIdent << " for (Standard_Integer " << anIterI << " = 1; " << anIterI << " <= aNb" << theLevel << "; " << anIterI << "++)\n" <<
1159 anIdent << " {\n" <<
1160 anIdent << " Standard_Integer subj" << theIndex << " = 0;\n" <<
1161 anIdent << " if ( theData->ReadSubList (aSub" << theIndex << ", " << anIterI << ", \"sub-part(" << theSTEPName << ")\", theCheck, subj" << theIndex << ") ) {\n" <<
1162 anIdent << " Standard_Integer aNum" << aLevel + 2 << " = subj" << theIndex << ";\n" <<
1163 anIdent << " for (Standard_Integer " << anIterJ << " = 1; " << anIterJ << " <= nbj" << theLevel << "; " << anIterJ << "++)\n" <<
1165 TCollection_AsciiString aSubName = typeToSTEPName (aComplex2->Type());
1166 writeRWReadField (theOS, anIterJ, aSubName, aVar, aComplex2->Type(), aLevel + 2, Standard_False);
1167 theOS << anIdent << " a" << theVarName << "->SetValue(" << anIterI << "," << anIterJ << ", a" << aVar << ");\n" <<
1168 anIdent << " }\n" <<
1174 theOS << anIdent << " a" << theVarName << " = new " << aTypeCPPName << "(1, aNb" << theLevel << ");\n" <<
1175 anIdent << " Standard_Integer aNum" << aLevel << " = aSub" << theIndex << ";\n" <<
1176 anIdent << " for (Standard_Integer " << anIterI << " = 1; " << anIterI << " <= aNb" << theLevel << "; " << anIterI << "++)\n" <<
1178 TCollection_AsciiString aSubName = typeToSTEPName (aComplex->Type());
1179 writeRWReadField (theOS, anIterI, aSubName, aVar, aComplex->Type(), aLevel, Standard_False);
1180 theOS << anIdent << " a" << theVarName << "->SetValue(" << anIterI << ", a" << aVar << ");\n";
1182 theOS << anIdent << " }\n" <<
1185 else if (aType->IsKind (STANDARD_TYPE(Express_String)))
1187 if (theSTEPName.Length() + theVarName.Length() < 70)
1189 theOS << anIdent << "theData->ReadString (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck, a" << theVarName << ");\n";
1193 theOS << anIdent << "theData->ReadString (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck,\n" <<
1194 anIdent << " a" << theVarName << ");\n";
1197 else if (aType->IsKind (STANDARD_TYPE(Express_Logical)))
1199 theOS << anIdent << "theData->ReadLogical (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck, a" << theVarName << ");\n";
1201 else if (aType->IsKind (STANDARD_TYPE(Express_Boolean)))
1203 theOS << anIdent << "theData->ReadBoolean (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck, a" << theVarName << ");\n";
1205 else if (aType->IsKind (STANDARD_TYPE(Express_Number)) || aType->IsKind (STANDARD_TYPE(Express_Integer)))
1207 theOS << anIdent << "theData->ReadInteger (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck, a" << theVarName << ");\n";
1209 else if (aType->IsKind (STANDARD_TYPE(Express_Real)))
1211 theOS << anIdent << "theData->ReadReal (" << aParam << ", " << theIndex << ", \"" << theSTEPName << "\", theCheck, a" << theVarName << ");\n";
1216 anIdent.Remove (1, 2);
1217 theOS << anIdent << "}\n" <<
1218 anIdent << "else\n" <<
1220 anIdent << " has" << theVarName << " = Standard_False;\n" <<
1221 anIdent << " a" << theVarName;
1222 if (aType->IsHandle())
1224 theOS << ".Nullify();";
1226 else if (aType->IsStandard())
1232 theOS << " = " << aTypeCPPName << "();";
1235 theOS << anIdent << "}\n";
1239 //=======================================================================
1240 // function : WriteRWReadCode
1242 //=======================================================================
1244 Standard_Integer Express_Entity::writeRWReadCode (Standard_OStream& theOS,
1245 const Standard_Integer theStart,
1246 const Standard_Integer theOwn) const
1248 Standard_Integer aNum = theStart;
1250 // write code for reading inherited fields
1251 for (Standard_Integer i = 1; i <= myInherit->Length(); i++)
1253 aNum = myInherit->Value (i)->writeRWReadCode (theOS, aNum, Standard_False);
1256 // write code for reading own fields
1257 if (myFields->Length() > 0)
1261 theOS << " // " << (theOwn ? "Own" : "Inherited") << " fields of " << Name() << "\n";
1264 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
1266 Handle(Express_Field) aField = myFields->Value (i);
1267 TCollection_AsciiString aSTEPName = Express::ToStepName (aField->Name());
1270 aSTEPName.Prepend (Express::ToStepName (Name().Cat (".")));
1272 TCollection_AsciiString aVarName (aField->Name());
1275 aVarName.Prepend (Name().Cat ("_"));
1278 writeRWReadField (theOS, TCollection_AsciiString (aNum), aSTEPName, aVarName, aField->Type(), 0, aField->IsOptional());
1285 //=======================================================================
1286 // function : WriteRWWriteField
1288 //=======================================================================
1290 static void writeRWWriteField (Standard_OStream& theOS,
1291 const TCollection_AsciiString& theVarName,
1292 const Handle(Express_Type)& theVarType,
1293 const Standard_Integer theIndex,
1294 const Standard_Integer theLevel)
1297 TCollection_AsciiString anIdent (" ");
1298 Standard_Integer aLevel = 0;
1299 for (; aLevel < theLevel; aLevel++)
1305 // decode aliased types
1306 Handle(Express_Type) aType = theVarType;
1307 while (aType->IsKind (STANDARD_TYPE(Express_NamedType)))
1309 Handle(Express_NamedType) aNamedType = Handle(Express_NamedType)::DownCast (aType);
1310 if (!aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Alias)))
1314 Handle(Express_Alias) anAlias = Handle(Express_Alias)::DownCast (aNamedType->Item());
1315 aType = anAlias->Type();
1318 // write variable depending on its type
1319 if (aType->IsKind (STANDARD_TYPE(Express_ComplexType)))
1321 Handle(Express_ComplexType) aComplex = Handle(Express_ComplexType)::DownCast (aType);
1322 aType = aComplex->Type();
1323 TCollection_AsciiString aVar (theLevel);
1324 aVar.Prepend ("aVar");
1325 theOS << anIdent << "theSW.OpenSub();\n" <<
1326 anIdent << "for (Standard_Integer i" << theIndex << " = 1; i" << theIndex << " <= ";
1327 if (aType->IsKind (STANDARD_TYPE(Express_ComplexType)))
1330 Handle(Express_ComplexType) complex2 = Handle(Express_ComplexType)::DownCast (aType);
1331 aType = complex2->Type();
1332 theOS << theVarName << "->RowLength(); i" << theIndex << "++)\n" <<
1334 anIdent << " theSW.NewLine(Standard_False);\n" <<
1335 anIdent << " theSW.OpenSub();\n" <<
1336 anIdent << " for (Standard_Integer j" << theIndex << " = 1; j" << theIndex << " <= " << theVarName << "->ColLength(); j" << theIndex << "++)\n" <<
1337 anIdent << " {\n" <<
1338 anIdent << " " << (aType->IsHandle() ? " Handle(" : " ") << aType->CPPName() << (aType->IsHandle() ? ") " : " ") << aVar << " = " << theVarName << "->Value (i" << theIndex << ", j" << theIndex << ");\n";
1339 writeRWWriteField (theOS, aVar, aType, theIndex + 1, aLevel + 1);
1340 theOS << anIdent << " }\n" <<
1341 anIdent << " theSW.CloseSub();\n";
1346 theOS << theVarName << "->Length(); i" << theIndex << "++)\n" <<
1348 anIdent << (aType->IsHandle() ? " Handle(" : " ") << aType->CPPName() << (aType->IsHandle() ? ") " : " ") << aVar << " = " << theVarName << "->Value (i" << theIndex << ");\n";
1349 writeRWWriteField (theOS, aVar, aType, theIndex + 1, aLevel);
1351 theOS << anIdent << "}\n" <<
1352 anIdent << "theSW.CloseSub();\n";
1354 else if (aType->IsKind (STANDARD_TYPE(Express_Boolean)))
1356 theOS << anIdent << "theSW.SendBoolean (" << theVarName << ");\n";
1358 else if (aType->IsKind (STANDARD_TYPE(Express_Logical)))
1360 theOS << anIdent << "theSW.SendLogical (" << theVarName << ");\n";
1364 Handle(Express_NamedType) aNamedType = Handle(Express_NamedType)::DownCast (aType);
1365 if (!aNamedType.IsNull() && aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Enum)))
1367 Handle(Express_Enum) anEnum = Handle(Express_Enum)::DownCast (aNamedType->Item());
1368 TCollection_AsciiString aPrefix = Express::EnumPrefix (anEnum->Name());
1369 Handle(TColStd_HSequenceOfHAsciiString) aNames = anEnum->Names();
1370 TCollection_AsciiString anEnumPack = anEnum->GetPackageName();
1371 theOS << anIdent << "switch (" << theVarName << ")\n";
1372 theOS << anIdent << "{\n";
1373 for (Standard_Integer i = 1; i <= aNames->Length(); i++)
1375 TCollection_AsciiString anEnumName = Express::ToStepName (aNames->Value (i)->String());
1376 anEnumName.UpperCase();
1377 theOS << anIdent << " case " << anEnumPack << "_" << aPrefix << aNames->Value (i)->String() << ": theSW.SendEnum (\"." << anEnumName << ".\"); break;\n";
1379 theOS << anIdent << "}\n";
1383 theOS << anIdent << "theSW.Send (" << theVarName;
1384 if (!aNamedType.IsNull() && aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Select)))
1386 theOS << ".Value()";
1393 //=======================================================================
1394 // function : WriteRWWriteCode
1396 //=======================================================================
1398 Standard_Integer Express_Entity::writeRWWriteCode (Standard_OStream& theOS,
1399 const Standard_Integer theStart,
1400 const Standard_Integer theOwn) const
1402 Standard_Integer aNum = theStart;
1404 // write code for writing inherited fields
1405 for (Standard_Integer i = 1; i <= myInherit->Length(); i++)
1407 aNum = myInherit->Value (i)->writeRWWriteCode (theOS, aNum, (i > 1 ? -1 : 1));
1410 // write code for writing own fields
1411 if (myFields->Length() > 0)
1414 " // " << (theOwn == 1 ? "Own" : "Inherited") << " fields of " << Name() << "\n";
1417 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
1419 Handle(Express_Field) aField = myFields->Value (i);
1420 TCollection_AsciiString aVarName (aField->Name());
1423 aVarName.Prepend (CPPName().Cat ("::"));
1425 else if (theOwn == -1)
1427 // inherited base class implemented as field
1428 aVarName.Prepend (Name().Cat ("()->"));
1430 aVarName.Prepend ("theEnt->");
1434 if (aField->IsOptional())
1436 theOS << " if (theEnt->";
1439 theOS << CPPName() << "::";
1441 else if (theOwn == -1)
1443 theOS << Name() << "()->";
1445 theOS << "Has" << aField->Name() << "())\n";
1448 writeRWWriteField (theOS, aVarName, aField->Type(), aNum, (aField->IsOptional() ? 1 : 0));
1449 if (aField->IsOptional())
1454 " theSW.SendUndef();\n"
1463 //=======================================================================
1464 // function : WriteRWShareField
1466 //=======================================================================
1468 static Standard_Boolean writeRWShareField (Standard_OStream& theOS,
1469 const TCollection_AsciiString& theVarName,
1470 const Handle(Express_Type)& theVarType,
1471 const Standard_Integer theIndex,
1472 const Standard_Integer theLevel)
1475 TCollection_AsciiString anIdent (" ");
1476 Standard_Integer aLevel = 0;
1477 for (; aLevel < theLevel; aLevel++)
1483 // decode aliased types
1484 Handle(Express_Type) aType = theVarType;
1485 while (aType->IsKind (STANDARD_TYPE(Express_NamedType)))
1487 Handle(Express_NamedType) aNamedType = Handle(Express_NamedType)::DownCast (aType);
1488 if (!aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Alias)))
1492 Handle(Express_Alias) anAlias = Handle(Express_Alias)::DownCast (aNamedType->Item());
1493 aType = anAlias->Type();
1496 // write variable depending on its type
1497 if (aType->IsKind (STANDARD_TYPE(Express_ComplexType)))
1499 Handle(Express_ComplexType) aComplex = Handle(Express_ComplexType)::DownCast (aType);
1500 aType = aComplex->Type();
1501 TCollection_AsciiString aVar (theLevel);
1502 aVar.Prepend ("aVar");
1503 std::ostringstream aStringOS;
1504 if (!writeRWShareField (aStringOS, aVar, aType, theIndex + 1, aLevel))
1506 return Standard_False;
1508 theOS << anIdent << "for (Standard_Integer i" << theIndex << " = 1; i" << theIndex << " <= " << theVarName << "->Length(); i" << theIndex << "++)\n" <<
1510 anIdent << (aType->IsHandle() ? " Handle(" : " ") << aType->CPPName() << (aType->IsHandle() ? ") " : " ") << aVar << " = " << theVarName << "->Value (i" << theIndex << ");\n";
1511 theOS << aStringOS.str();
1512 theOS << anIdent << "}\n";
1513 return Standard_True;
1515 if (aType->IsKind (STANDARD_TYPE(Express_NamedType)))
1517 Handle(Express_NamedType) aNamedType = Handle(Express_NamedType)::DownCast (aType);
1518 if (aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Entity)))
1520 theOS << anIdent << "theIter.AddItem (" << theVarName << ");\n";
1521 return Standard_True;
1523 if (aNamedType->Item()->IsKind (STANDARD_TYPE(Express_Select)))
1525 theOS << anIdent << "theIter.AddItem (" << theVarName << ".Value());\n";
1526 return Standard_True;
1530 return Standard_False;
1533 //=======================================================================
1534 // function : WriteRWShareCode
1536 //=======================================================================
1538 Standard_Integer Express_Entity::writeRWShareCode (Standard_OStream& theOS,
1539 const Standard_Integer theStart,
1540 const Standard_Integer theOwn) const
1542 Standard_Integer aNum = theStart;
1544 // write code for sharing inherited fields
1545 for (Standard_Integer i = 1; i <= myInherit->Length(); i++)
1547 aNum = myInherit->Value (i)->writeRWShareCode (theOS, aNum, (i > 1 ? -1 : Standard_False));
1550 // write code for sharing own fields
1551 if (myFields->Length() > 0)
1554 " // " << (theOwn == 1 ? "Own" : "Inherited") << " fields of " << Name() << "\n";
1557 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
1559 Handle(Express_Field) aField = myFields->Value (i);
1560 TCollection_AsciiString aVarName (aField->Name());
1563 aVarName.Prepend (CPPName().Cat ("::"));
1565 else if (theOwn == -1)
1567 // inherited base class implemented as field
1568 aVarName.Prepend (Name().Cat ("()->"));
1570 aVarName.Prepend ("theEnt->");
1573 std::ostringstream aStringOS;
1574 if (!writeRWShareField (aStringOS, aVarName, aField->Type(), aNum, (aField->IsOptional() ? 1 : 0)))
1580 if (aField->IsOptional())
1582 theOS << " if (theEnt->";
1584 theOS << CPPName() << "::";
1585 else if (theOwn == -1)
1586 theOS << Name() << "()->";
1587 theOS << "Has" << aField->Name() << "())\n"
1590 theOS << aStringOS.str();
1591 if (aField->IsOptional())
1600 //=======================================================================
1601 // function : MakeInit
1603 //=======================================================================
1605 Standard_Integer Express_Entity::makeInit (Standard_OStream& theOS,
1606 const Standard_Integer theShift,
1607 const Standard_Integer theOwn,
1608 const Standard_Integer theMode) const
1610 Standard_Integer aShift = theShift;
1612 // write code for inherited fields
1613 for (Standard_Integer i = 1; i <= myInherit->Length(); i++)
1615 Handle(Express_Entity) anEntity = myInherit->Value (i);
1616 const TCollection_AsciiString& anEntityCPPName = anEntity->CPPName();
1619 Standard_Integer aShift2 = 0;
1622 theOS << "\n my" << anEntity->Name() << " = new " << anEntityCPPName << ";"
1623 "\n my" << anEntity->Name() << "->Init (";
1624 aShift2 = 12 + anEntity->Name().Length();
1628 theOS << "\n " << anEntityCPPName << "::Init (";
1629 aShift2 = 10 + anEntityCPPName.Length();
1631 anEntity->makeInit (theOS, aShift2, Standard_False, 2);
1636 aShift = anEntity->makeInit (theOS, aShift, (i > 1 ? -1 : Standard_False), theMode);
1640 // write code for own fields
1641 for (Standard_Integer i = 1; i <= myFields->Length(); i++)
1643 Handle(Express_Field) aField = myFields->Value (i);
1644 Handle(Express_Type) aFieldType = aField->Type();
1645 TCollection_AsciiString aVarName(aField->Name());
1648 aVarName.Prepend (Name().Cat ("_"));
1651 // make CR and indent
1652 TCollection_AsciiString aSpaces = "";
1653 for (Standard_Integer aSpaceNum = 0; aSpaceNum < abs (aShift); aSpaceNum++)
1657 Standard_Character aDelim = (theMode == 0 ? ',' : (theMode == 3 ? '\n' : ','));
1660 if (i == 1 && myInherit->Length() == 0 && theMode == 3)
1662 theOS << aDelim << aSpaces;
1664 else if (theMode == 4)
1670 theOS << aDelim << "\n" << aSpaces;
1678 if (aField->IsOptional())
1682 theOS << "const Standard_Boolean theHas" << aVarName << ",\n" << aSpaces;
1684 else if (theMode == 1)
1686 theOS << "const Standard_Boolean theHas" << aVarName << ",\n" << aSpaces;
1688 else if (theMode == 2)
1690 theOS << "has" << aVarName << ",\n" << aSpaces;
1692 else if (theMode == 4)
1694 theOS << "has" << aVarName << ", ";
1699 if (theMode == 0 || theMode == 1)
1701 theOS << "const " << (aFieldType->IsHandle() ? "Handle(" : "") << aFieldType->CPPName() << (aFieldType->IsHandle() ? ")" : "") <<
1702 (aFieldType->IsSimple() ? " the" : "& the") << aVarName;
1704 else if (theMode == 2)
1706 theOS << "the" << aVarName;
1708 else if (theMode == 4)
1710 theOS << "a" << aVarName;
1714 if (aField->IsOptional())
1716 theOS << "myHas" << aField->Name() << " = theHas" << aVarName << ";\n"
1717 " if (myHas" << aField->Name() << ")\n"
1719 " my" << aField->Name() << " = the" << aVarName << ";\n"
1723 " my" << aField->Name();
1724 if (aFieldType->IsHandle())
1726 theOS << ".Nullify();";
1728 else if (aFieldType->IsStandard())
1734 theOS << " = " << aFieldType->CPPName() << "();";
1740 theOS << "my" << aField->Name() << " = the" << aVarName << ";";
1752 //=======================================================================
1753 // function : SetAbstractFlag
1755 //=======================================================================
1757 void Express_Entity::SetAbstractFlag (const Standard_Boolean isAbstract)
1759 myIsAbstract = isAbstract;
1762 //=======================================================================
1763 // function : AbstractFlag
1765 //=======================================================================
1767 Standard_Boolean Express_Entity::AbstractFlag() const
1769 return myIsAbstract;