1 // Copyright (c) 2022 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <RWStl_ConfigurationNode.hxx>
16 #include <DE_ConfigurationContext.hxx>
17 #include <NCollection_Buffer.hxx>
18 #include <RWStl_Provider.hxx>
20 IMPLEMENT_STANDARD_RTTIEXT(RWStl_ConfigurationNode, DE_ConfigurationNode)
24 static const TCollection_AsciiString& THE_CONFIGURATION_SCOPE()
26 static const TCollection_AsciiString aScope = "provider";
31 //=======================================================================
32 // function : STEPCAFControl_ConfigurationNode
34 //=======================================================================
35 RWStl_ConfigurationNode::RWStl_ConfigurationNode() :
36 DE_ConfigurationNode()
41 //=======================================================================
42 // function : STEPCAFControl_ConfigurationNode
44 //=======================================================================
45 RWStl_ConfigurationNode::RWStl_ConfigurationNode(const Handle(RWStl_ConfigurationNode)& theNode)
46 :DE_ConfigurationNode(theNode)
48 InternalParameters = theNode->InternalParameters;
52 //=======================================================================
55 //=======================================================================
56 bool RWStl_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theResource)
58 TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor();
60 InternalParameters.ReadMergeAngle =
61 theResource->RealVal("read.merge.angle", InternalParameters.ReadMergeAngle, aScope);
62 InternalParameters.ReadBRep =
63 theResource->BooleanVal("read.brep", InternalParameters.ReadBRep, aScope);
64 InternalParameters.WriteAscii =
65 theResource->BooleanVal("write.ascii", InternalParameters.WriteAscii, aScope);
69 //=======================================================================
72 //=======================================================================
73 TCollection_AsciiString RWStl_ConfigurationNode::Save() const
75 TCollection_AsciiString aResult;
76 aResult += "!*****************************************************************************\n";
77 aResult = aResult + "!Configuration Node " + " Vendor: " + GetVendor() + " Format: " + GetFormat() + "\n";
78 TCollection_AsciiString aScope = THE_CONFIGURATION_SCOPE() + "." + GetFormat() + "." + GetVendor() + ".";
81 aResult += "!Read parameters:\n";
85 aResult += "!Input merge angle value\n";
86 aResult += "!Default value (in degrees): 90.0. Angle should be within [0.0, 90.0] range\n";
87 aResult += aScope + "read.merge.angle :\t " + InternalParameters.ReadMergeAngle + "\n";
91 aResult += "!Setting up Boundary Representation flag\n";
92 aResult += "!Default value: false. Available values: \"on\", \"off\"\n";
93 aResult += aScope + "read.brep :\t " + InternalParameters.ReadBRep + "\n";
97 aResult += "!Write parameters:\n";
101 aResult += "!Setting up writing mode (Ascii or Binary)\n";
102 aResult += "!Default value: 1(Binary). Available values: 0(Ascii), 1(Binary)\n";
103 aResult += aScope + "write.ascii :\t " + InternalParameters.WriteAscii + "\n";
106 aResult += "!*****************************************************************************\n";
110 //=======================================================================
113 //=======================================================================
114 Handle(DE_ConfigurationNode) RWStl_ConfigurationNode::Copy() const
116 return new RWStl_ConfigurationNode(*this);
119 //=======================================================================
120 // function : BuildProvider
122 //=======================================================================
123 Handle(DE_Provider) RWStl_ConfigurationNode::BuildProvider()
125 return new RWStl_Provider(this);
128 //=======================================================================
129 // function : IsImportSupported
131 //=======================================================================
132 bool RWStl_ConfigurationNode::IsImportSupported() const
137 //=======================================================================
138 // function : IsExportSupported
140 //=======================================================================
141 bool RWStl_ConfigurationNode::IsExportSupported() const
146 //=======================================================================
147 // function : GetFormat
149 //=======================================================================
150 TCollection_AsciiString RWStl_ConfigurationNode::GetFormat() const
152 return TCollection_AsciiString("STL");
155 //=======================================================================
156 // function : GetVendor
158 //=======================================================================
159 TCollection_AsciiString RWStl_ConfigurationNode::GetVendor() const
161 return TCollection_AsciiString("OCC");
164 //=======================================================================
165 // function : GetExtensions
167 //=======================================================================
168 TColStd_ListOfAsciiString RWStl_ConfigurationNode::GetExtensions() const
170 TColStd_ListOfAsciiString anExt;
175 //=======================================================================
176 // function : CheckContent
178 //=======================================================================
179 bool RWStl_ConfigurationNode::CheckContent(const Handle(NCollection_Buffer)& theBuffer) const
181 if (theBuffer.IsNull() || theBuffer->Size() < 7)
185 const char* aBytes = (const char*)theBuffer->Data();
186 if (!(::strncmp(aBytes, "solid", 5) || ::strncmp(aBytes, "SOLID", 5)) && isspace(aBytes[5]))
190 // binary STL has no header for identification - format can be detected only by file extension