1 Coding Rules {#occt_dev_guides__coding_rules}
2 ======================================
6 @section occt_coding_rules_1 Introduction
8 The purpose of this document is to define a common programming style for Open CASCADE Technology.
10 The common style facilitates understanding and maintaining a code developed cooperatively by several programmers. In addition, it enables construction of tools that incorporate knowledge of these standards to help in the programming.
12 OCCT programming style follows common and appropriate best practices, so some guidelines have been excerpted from the public domain.
14 The guide can be improved in the future as new ideas and enhancements are added.
16 @subsection occt_coding_rules_1_1 Scope of the document
18 Rules in this document refer to C++ code. However, with minor exceptions due to language restrictions, they are applicable to any sources in Open CASCADE Technology framework, including:
22 - TCL scripts and test cases
24 @section occt_coding_rules_2 Naming Conventions
26 @subsection occt_coding_rules_2_1 General naming rules
28 The names considered in this section mainly refer to the interface of Open CASCADE Technology libraries or source code itself.
30 ### International language [MANDATORY]
32 Open CASCADE Technology is an open source platform available for an international community, thus all names need to be composed of English words or their abbreviations.
36 Names should be meaningful or, at least, contain a meaningful part. To better understand this requirement, let us examine the existing names of toolkits, packages, classes and methods:
37 - Packages containing words *Geom* or *Geom2d* in their names are related to geometrical data and operations.
38 - Packages containing words *TopoDS* or *BRep* in their names are related to topological data and operations.
39 - Packages ending with <i>...Test</i> define Draw Harness plugins.
40 - Methods starting with *Get...* and *Set...* are usually responsible for correspondingly retrieving and storing data.
44 Names related to a logically connected functionality should have the same prefix (start with the same letters) or, at least, have any other common part.
45 For example, method *GetCoord* returns a triple of real values and is defined for directions, vectors and points. The logical connection is obvious.
48 Camel Case style is preferred for names.
52 Standard_Integer awidthofbox; // this is bad
53 Standard_Integer width_of_box; // this is bad
54 Standard_Integer aWidthOfBox; // this is OK
57 @subsection occt_coding_rules_2_2 Names of development units
59 Usually a unit (e.g. a package) is a set of classes, methods, enumerations or any other sources implementing a common functionality, which is self-contained and independent from other parts of the library.
61 ### No underscores in unit names [MANDATORY]
63 Names of units should not contain underscores, unless the use of underscores is allowed explicitly.
65 ### File name extensions [MANDATORY]
67 The following extensions should be used for source files, depending on their type:
69 * <i>.cxx</i> -- C++ source files
70 * <i>.hxx</i> -- C++ header files
71 * <i>.lxx</i> -- additional headers containing definitions of inline methods and auxiliary code
73 ### Prefix for toolkit names [MANDATORY]
75 Toolkit names are prefixed by *TK*, followed by a meaningful part of the name explaining the domain of functionality covered by the toolkit (e.g. *TKOpenGl*).
79 Usually the names of source files located in a unit start from the unit name separated from the other part of the file name by underscore "_".
81 Thus, the names of files containing sources of C++ classes that belong to a package are constructed according to the following template:
84 <package-name>_<class-name>.cxx (or .hxx)
87 For example, file *Adaptor2d_Curve2d.cxx* belongs to the package *Adaptor2d*
89 Files that contain sources related to the whole unit are called by the unit name with appropriate extension.
91 ### Names of functions
93 The term **function** here is defined as:
96 - Any non-member procedure or function
98 It is preferred to start names of public methods from an upper case character and to start names of protected and private methods from a lower case character.
102 class MyPackage_MyClass
107 Standard_Integer Value() const;
108 void SetValue (const Standard_Integer theValue);
112 void setIntegerValue (const Standard_Integer theValue);
117 @subsection occt_coding_rules_2_3 Names of variables
119 There are several rules that describe currently accepted practices for naming variables.
121 ### Naming of variables
123 Name of a variable should not conflict with the existing or possible global names (for packages, macros, functions, global variables, etc.).
125 The name of a variable should not start with an underscore.
127 See the following examples:
130 Standard_Integer Elapsed_Time = 0; // this is bad - possible class name
131 Standard_Integer gp = 0; // this is bad - existing package name
132 Standard_Integer aGp = 0; // this is OK
133 Standard_Integer _KERNEL = 0; // this is bad
134 Standard_Integer THE_KERNEL = 0; // this is OK
137 ### Names of function parameters
139 The name of a function (procedure, class method) parameter should start with prefix *the* followed by the meaningful part of the name starting with a capital letter.
141 See the following examples:
144 void Package_MyClass::MyFunction (const gp_Pnt& p); // this is bad
145 void Package_MyClass::MyFunction (const gp_Pnt& theP); // this is OK
146 void Package_MyClass::MyFunction (const gp_Pnt& thePoint); // this is preferred
149 ### Names of class member variables
151 The name of a class member variable should start with prefix *my* followed by the meaningful of the name starting with a capital letter.
153 See the following examples:
156 Standard_Integer counter; // This is bad
157 Standard_Integer myC; // This is OK
158 Standard_Integer myCounter; // This is preferred
161 ### Names of global variables
163 It is strongly recommended to avoid defining any global variables.
164 However, as soon as a global variable is necessary, its name should be prefixed by the name of a class or a package where it is defined followed with <i>_my</i>.
166 See the following examples:
169 Standard_Integer MyPackage_myGlobalVariable = 0;
170 Standard_Integer MyPackage_MyClass_myGlobalVariable = 0;
173 Static constants within the file should be written in upper-case and begin with prefix *THE_*:
177 static const Standard_Real THE_CONSTANT_COEF = 3.14;
181 ### Names of local variables
183 The name of a local variable should be distinguishable from the name of a function parameter, a class member variable and a global variable.
185 It is preferred to prefix local variable names with *a* and *an* (or *is*, *to* and *has* for Boolean variables).
187 See the following example:
190 Standard_Integer theI; // this is bad
191 Standard_Integer i; // this is bad
192 Standard_Integer index; // this is bad
193 Standard_Integer anIndex; // this is OK
196 ### Avoid dummy names
197 Avoid dummy names, such as <i>i, j, k</i>. Such names are meaningless and easy to mix up.
199 The code becomes more and more complicated when such dummy names are used there multiple times with different meanings, or in cycles with different iteration ranges, etc.
201 See the following examples for preferred style:
204 void Average (const Standard_Real** theArray,
205 Standard_Integer theRowsNb,
206 Standard_Integer theRowLen,
207 Standard_Real& theResult)
210 for (Standard_Integer aRow = 0; aRow < aRowsNb; ++aRow)
212 for (Standard_Integer aCol = 0; aCol < aRowLen; ++aCol)
214 theResult += theArray[aRow][aCol];
216 theResult /= Standard_Real(aRowsNb * aRowLen);
221 @section occt_coding_rules_3 Formatting rules
223 To improve the open source readability and, consequently, maintainability, the following set of rules is applied.
225 ### International language [MANDATORY]
227 All comments in all sources must be in English.
231 Try to stay within the limit of 120 characters per line in all sources.
233 ### C++ style comments
235 Prefer C++ style comments in C++ sources.
237 ### Commenting out unused code
239 Delete unused code instead of commenting it or using \#define.
241 ### Indentation in sources [MANDATORY]
243 Indentation in all sources should be set to two space characters.
244 Use of tabulation characters for indentation is disallowed.
246 ### Separating spaces
248 Punctuation rules follow the rules of the English language.
249 * C/C++ reserved words, commas, colons and semicolons should be followed by a space character if they are not at the end of a line.
250 * There should be no space characters after '(' and before ')'. Closing and opening brackets should be separated by a space character.
251 * For better readability it is also recommended to surround conventional operators by a space character. See the following examples:
254 while (true) // NOT: while( true ) ...
256 DoSomething (theA, theB, theC, theD); // NOT: DoSomething(theA,theB,theC,theD);
258 for (anIter = 0; anIter < 10; ++anIter) // NOT: for (anIter=0;anIter<10;++anIter){
260 theA = (theB + theC) * theD; // NOT: theA=(theB+theC)*theD
264 ### Separate logical blocks
266 Separate logical blocks of code with one blank line and comments.
268 See the following example:
272 Standard_Integer anArgsNb = argCount();
273 if (anArgsNb < 3 || isSmthInvalid)
275 return THE_ARG_INVALID;
278 // read and check header
287 Notice that multiple blank lines should be avoided.
289 ### Separate function bodies [MANDATORY]
291 Use function descriptive blocks to separate function bodies from each other.
292 Each descriptive block should contain at least a function name and purpose description.
294 See the following example:
297 // =======================================================================
298 // function : TellMeSmthGood
299 // purpose : Gives me good news
300 // =======================================================================
301 void TellMeSmthGood()
306 // =======================================================================
307 // function : TellMeSmthBad
308 // purpose : Gives me bad news
309 // =======================================================================
316 ### Block layout [MANDATORY]
317 Figure brackets <i>{ }</i> and each operator <i>(for, if, else, try, catch)</i> should be written on a dedicated line.
319 In general, the layout should be as follows:
328 Entering a block increases and leaving a block decreases the indentation by one tabulation.
330 ### Single-line operators
332 Single-line conditional operators <i>(if, while, for,</i> etc.) can be written without brackets on the following line.
335 if (!myIsInit) return Standard_False; // bad
337 if (thePtr == NULL) // OK
338 return Standard_False;
340 if (!theAlgo.IsNull()) // preferred
346 Having all code in the same line is less convenient for debugging.
350 Use alignment wherever it enhances the readability. See the following example:
353 MyPackage_MyClass anObject;
354 Standard_Real aMinimum = 0.0;
355 Standard_Integer aVal = theVal;
358 case 0: computeSomething(); break;
359 case 12: computeSomethingElse (aMinimum); break;
361 default: computeSomethingElseYet(); break;
365 ### Indentation of comments
367 Comments should be indented in the same way as the code to which they refer or they can be in the same line if they are short.
369 The text of the comment should be separated from the slash character by a single space character.
371 See the following example:
374 while (expression) //bad comment
376 // this is a long multi-line comment
377 // which is really required
378 DoSomething(); // maybe, enough
379 DoSomethingMore(); // again
383 ### Early return statement
385 Use an early return condition rather than collect indentations.
390 Standard_Integer ComputeSumm (const Standard_Integer* theArray,
391 const Standard_Size theSize)
393 Standard_Integer aSumm = 0;
394 if (theArray == NULL || theSize == 0)
399 ... computing summ ...
407 Standard_Integer ComputeSumm (const Standard_Integer* theArray,
408 const Standard_Size theSize)
410 Standard_Integer aSumm = 0;
411 if (theArray != NULL && theSize != 0)
413 ... computing summ ...
419 This helps to improve readability and reduce the unnecessary indentation depth.
423 Trailing spaces should be removed whenever possible.
424 Spaces at the end of a line are useless and do not affect functionality.
428 Split headers into groups: system headers, headers per each framework, project headers; sort the list of includes alphabetically.
430 This rule improves readability, allows detecting useless multiple header inclusions and makes 3rd-party dependencies clearly visible.
438 #include <QDataStream>
442 #include <gp_Pnt.hxx>
443 #include <gp_Vec.hxx>
444 #include <NCollection_List.hxx>
447 @section occt_coding_rules_4 Documentation rules
449 The source code is one of the most important references for documentation.
450 The comments in the source code should be complete enough to allow understanding the corresponding code and to serve as basis for other documents.
452 The main reasons why the comments are regarded as documentation and should be maintained are:
453 - The comments are easy to reach -- they are always together with the source code;
454 - It is easy to update a description in the comment when the source is modified;
455 - The source by itself is a good context to describe various details that would require much more explanations in a separate document;
456 - As a summary, this is the most cost-effective documentation.
458 The comments should be compatible with Doxygen tool for automatic documentation generation (thus should use compatible tags).
460 ### Documenting classes [MANDATORY]
462 Each class should be documented in its header file (.hxx).
463 The comment should give enough details for the reader to understand the purpose of the class and the main way of work with it.
465 ### Documenting class methods [MANDATORY]
467 Each class or package method should be documented in the header file (.hxx).
469 The comment should explain the purpose of the method, its parameters, and returned value(s).
473 //! Method computes the square value.
474 //! @param theValue the input value
475 //! @return squared value
476 Standard_Export Standard_Real Square (Standard_Real theValue);
479 ### Documenting C/C++ sources
481 It is very desirable to put comments in the C/C++ sources of the package/class.
483 They should be detailed enough to allow any person to understand what each part of code does.
485 It is recommended to comment all static functions (like methods in headers), and to insert at least one comment per each 10-100 lines in the function body.
487 There are also some rules that define how comments should be formatted, see @ref occt_coding_rules_3 "Formatting Rules".
489 Following these rules is important for good comprehension of the comments. Moreover, this approach allows automatically generating user-oriented documentation directly from the commented sources.
491 @section occt_coding_rules_5 Application design
493 The following rules define the common style, which should be applied by any developer contributing to the open source.
495 ### Allow possible inheritance
497 Try to design general classes (objects) keeping possible inheritance in mind.
498 This rule means that the user who makes possible extensions of your class should not encounter problems of private implementation.
499 Try to use protected members and virtual methods wherever you expect extensions in the future.
501 ### Avoid friend declarations
503 Avoid using 'friend' classes or functions except for some specific cases (for example, iteration) 'Friend' declarations increase coupling.
507 Avoid providing set/get methods for all fields of the class.
508 Intensive set/get functions break down encapsulation.
510 ### Hiding virtual functions [MANDATORY]
512 Avoid hiding a base class virtual function by a redefined function with a different signature.
513 Most of the compilers issue warning on this.
515 ### Avoid mixing error reporting strategies
517 Try not to mix different error indication/handling strategies (exceptions or returned values) on the same application level.
519 ### Minimize compiler warnings [MANDATORY]
521 When compiling the source pay attention to and try to minimize compiler warnings.
523 ### Avoid unnecessary inclusions
525 Try to minimize compilation dependencies by removing unnecessary inclusions.
527 @section occt_coding_rules_6 General C/C++ rules
529 This section defines the rules for writing a portable and maintainable C/C++ source code.
531 ### Wrapping of global variables [MANDATORY]
533 Use package or class methods returning reference to wrap global variables to reduce possible name space conflicts.
535 ### Avoid private members
537 Use *protected* members instead of *private* wherever reasonable to enable future extensions.
538 Use *private* fields if future extensions should be disabled.
540 ### Constants and inlines over defines [MANDATORY]
542 Use constant variables (const) and inline functions instead of defines (\#define).
544 ### Avoid explicit numerical values [MANDATORY]
546 Avoid usage of explicit numeric values. Use named constants and enumerations instead.
547 Numbers produce difficulties for reading and maintenance.
549 ### Three mandatory methods
551 If a class has a destructor, an assignment operator or a copy constructor, it usually needs the other two methods.
553 ### Virtual destructor
555 A class with virtual function(s) ought to have a virtual destructor.
557 ### Overriding virtual methods
559 Declaration of overriding method should contains specifiers "virtual" and "override"
560 (using Standard_OVERRIDE alias for compatibility with old compilers).
563 class MyPackage_BaseClass
568 Standard_EXPORT virtual Standard_Boolean Perform();
573 class MyPackage_MyClass : public MyPackage_BaseClass
578 Standard_EXPORT virtual Standard_Boolean Perform() Standard_OVERRIDE;
583 This makes class definition more clear (virtual methods become highlighted).
585 Declaration of interface using pure virtual functions protects against
586 incomplete inheritance at first level, but does not help when method is overridden multiple times within nested inheritance
587 or when method in base class is intended to be optional.
589 And here "override" specifier introduces additional protection against situations when interface changes might be missed
590 (class might contain old methods which will be never called).
592 ### Default parameter value
594 Do not redefine a default parameter value in an inherited function.
596 ### Use const modifier
598 Use *const* modifier wherever possible (functions parameters, return values, etc.)
600 ### Usage of goto [MANDATORY]
601 Avoid *goto* statement unless it is really needed.
603 ### Declaring variable in for() header
605 Declare a cycle variable in the header of the *for()* statement if not used out of cycle.
608 Standard_Real aMinDist = Precision::Infinite();
609 for (NCollection_Sequence<gp_Pnt>::Iterator aPntIter (theSequence);
610 aPntIter.More(); aPntIter.Next())
612 aMinDist = Min (aMinDist, theOrigin.Distance (aPntIter.Value()));
616 ### Condition statements within zero
618 Avoid usage of C-style comparison for non-boolean variables:
621 void Function (Standard_Integer theValue,
622 Standard_Real* thePointer)
624 if (!theValue) // bad style - ambiguous logic
629 if (theValue == 0) // OK
634 if (thePointer != NULL) // OK, predefined NULL makes pointer comparison cleaner to reader
635 { // (nullptr should be used instead as soon as C++11 will be available)
641 @section occt_coding_rules_7 Portability issues
643 This chapter contains rules that are critical for cross-platform portability.
645 ### Provide code portability [MANDATORY]
647 The source code must be portable to all platforms listed in the official 'Technical Requirements'.
648 The term 'portable' here means 'able to be built from source'.
650 The C++ source code should meet C++03 standard.
651 Any usage of compiler-specific features or further language versions (for example, C++11, until all major compilers on all supported platforms implement all its features) should be optional (used only with appropriate preprocessor checks) and non-exclusive (an alternative implementation compatible with other compilers should be provided).
653 ### Avoid usage of global variables [MANDATORY]
655 Avoid usage of global variables. Usage of global variables may cause problems when accessed from another shared library.
657 Use global (package or class) functions that return reference to static variable local to this function instead of global variables.
659 Another possible problem is the order of initialization of global variables defined in various libraries that may differ depending on platform, compiler and environment.
661 ### Avoid explicit basic types
663 Avoid explicit usage of basic types (*int*, *float*, *double*, etc.), use Open CASCADE Technology types from package *Standard: Standard_Integer, Standard_Real, Standard_ShortReal, Standard_Boolean, Standard_CString* and others or a specific *typedef* instead.
665 ### Use *sizeof()* to calculate sizes [MANDATORY]
667 Do not assume sizes of types. Use *sizeof()* instead to calculate sizes.
669 ### Empty line at the end of file [MANDATORY]
671 In accordance with C++03 standard source files should be trailed by an empty line.
672 It is recommended to follow this rule for any plain text files for consistency and for correct work of git difference tools.
674 @section occt_coding_rules_8 Stability issues
676 The rules listed in this chapter are important for stability of the programs that use Open CASCADE Technology libraries.
678 ### Use *OSD::SetSignal()* to catch exceptions
680 When using Open CASCADE Technology in an application, call *OSD::SetSignal()* function when the application is initialized.
682 This will install C handlers for run-time interrupt signals and exceptions, so that low-level exceptions (such as access violation, division by zero, etc.) will be redirected to C++ exceptions
683 that use *try {...} catch (Standard_Failure) {...}* blocks.
685 The above rule is especially important for robustness of modeling algorithms.
687 ### Cross-referenced handles
689 Take care about cycling of handled references to avoid chains, which will never be freed. For this purpose, use a pointer at one (subordinate) side.
691 See the following example:
696 class Master : public Standard_Transient
699 void SetSlave (const Handle(Slave)& theSlave)
705 Handle(Slave) theSlave; // smart pointer
709 class Slave : public Standard_Transient
712 void SetMaster (const Handle(Master)& theMaster)
714 myMaster = theMaster.get();
718 Master* theMaster; // simple pointer
723 ### C++ memory allocation
725 In C++ use *new* and *delete* operators instead of *malloc()* and *free()*. Try not to mix different memory allocation techniques.
727 ### Match *new* and *delete* [MANDATORY]
729 Use the same form of new and delete.
732 aPtr1 = new TypeA[n]; ... ; delete[] aPtr1;
733 aPtr2 = new TypeB(); ... ; delete aPtr2;
734 aPtr3 = Standard::Allocate (4096); ... ; Standard::Free (aPtr3);
737 ### Methods managing dynamical allocation [MANDATORY]
739 Define a destructor, a copy constructor and an assignment operator for classes with dynamically allocated memory.
741 ### Uninitialized variables [MANDATORY]
743 Every variable should be initialized.
746 Standard_Integer aTmpVar1; // bad
747 Standard_Integer aTmpVar2 = 0; // OK
750 Uninitialized variables might be kept only within performance-sensitive code blocks and only when their initialization is guaranteed by subsequent code.
752 ### Do not hide global *new*
754 Avoid hiding the global *new* operator.
756 ### Assignment operator
758 In *operator=()* assign to all data members and check for assignment to self.
762 Don't check floats for equality or non-equality; check for GT, GE, LT or LE.
765 if (Abs (theFloat1 - theFloat2) < theTolerance)
771 Package *Precision* provides standard values for SI units and widely adopted by existing modeling algorithms:
773 - *Precision::Confusion()* for lengths in meters;
774 - *Precision::Angular()* for angles in radians.
776 as well as definition of infinite values within normal range of double precision:
777 - *Precision::Infinite()*
778 - *Precision::IsInfinite()*
779 - *Precision::IsPositiveInfinite()*
780 - *Precision::IsNegativeInfinite()*
782 ### Non-indexed iteration
784 Avoid usage of iteration over non-indexed collections of objects.
785 If such iteration is used, make sure that the result of the algorithm does not depend on the order of iterated items.
787 Since the order of iteration is unpredictable in case of a non-indexed collection of objects, it frequently leads to different behavior of the application from one run to another, thus embarrassing the debugging process.
789 It mostly concerns mapped objects for which pointers are involved in calculating the hash function. For example, the hash function of *TopoDS_Shape* involves the address of *TopoDS_TShape* object. Thus the order of the same shape in the *TopTools_MapOfShape* will vary in different sessions of the application.
791 ### Do not throw in destructors
793 Do not throw from within a destructor.
795 ### Assigning to reference [MANDATORY]
797 Avoid the assignment of a temporary object to a reference. This results in a different behavior for different compilers on different platforms.
799 @section occt_coding_rules_9 Performance issues
801 These rules define the ways of avoiding possible loss of performance caused by ineffective programming.
803 ### Class fields alignment
805 Declare fields of a class in the decreasing order of their size for better alignment.
806 Generally, try to reduce misaligned accesses since they impact the performance (for example, on Intel machines).
808 ### Fields initialization order [MANDATORY]
810 List class data members in the constructor's initialization list in the order they are declared.
813 class MyPackage_MyClass
823 // : myPropertyB (2),
824 // myPropertyA (1) {}
828 Standard_Integer myPropertyA;
829 Standard_Integer myPropertyB;
834 ### Initialization over assignment
836 Prefer initialization over assignment in class constructors.
840 : myPropertyA (1) // preferred
842 myPropertyB = 2; // not recommended
848 When programming procedures with extensive memory access, try to optimize them in terms of cache behavior. Here is an example of how the cache behavior can be impacted:
853 Standard_Real anArray[4096][2];
854 for (Standard_Integer anIter = 0; anIter < 4096; ++anIter)
856 anArray[anIter][0] = anArray[anIter][1];
860 is more efficient then
863 Standard_Real anArray[2][4096];
864 for (Standard_Integer anIter = 0; anIter < 4096; ++anIter)
866 anArray[0][anIter] = anArray[1][anIter];
870 since linear access does not invalidate cache too often.
872 @section occt_coding_rules_10 Draw Harness command
874 Draw Harness provides TCL interface for OCCT algorithms.
876 There is no TCL wrapper over OCCT C++ classes, instead interface is provided through the set of TCL commands implemented in C++.
878 There is a list of common rules which should be followed to implement well-formed Draw Harness command.
882 Command should return 0 in most cases even if the executed algorithm has failed. Returning 1 would lead to a TCL exception, thus should be used in case of a command line syntax error and similar issues.
884 ### Validate input parameters
886 Command arguments should be validated before usage. The user should see a human-readable error description instead of a runtime exception from the executed algorithm.
888 ### Validate the number of input parameters
890 Command should warn the user about unknown arguments, including cases when extra parameters have been pushed for the command with a fixed number of arguments.
895 std::cout << "Syntax error - wrong number of arguments!\n";
899 Standard_Integer anArgIter = 1;
900 Standard_CString aResName = theArgVec[anArgIter++];
901 Standard_CString aFaceName = theArgVec[anArgIter++];
902 TopoDS_Shape aFaceShape = DBRep::Get (aFaceName);
903 if (aFaceShape.IsNull()
904 || aFaceShape.ShapeType() != TopAbs_FACE)
906 std::cout << "Shape " << aFaceName << " is empty or not a Face!\n";
909 DBRep::Set (aResName, aFaceShape);
915 Informative messages should be printed into standard output *std::cout*, whilst command results (if any) -- into Draw Interpreter.
917 Information printed into Draw Interpreter should be well-structured to allow usage in TCL script.
919 ### Long list of arguments
921 Any command with a long list of obligatory parameters should be considered as ill-formed by design.
922 Optional parameters should start with flag name (with '-' prefix) and followed by its values:
925 myCommand -flag1 value1 value2 -flag2 value3
930 - Integer values should be read using *Draw::Atoi()* function.
931 - Real values should be read using *Draw::Atof()* function.
932 - Flags names should be checked in case insensitive manner.
934 Functions *Draw::Atof()* and *Draw::Atoi()* support expressions and read values in C-locale.
937 Standard_Real aPosition[3] = {0.0, 0.0, 0.0};
938 for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter)
940 Standard_CString anArg = theArgVec[anArgIter];
941 TCollection_AsciiString aFlag (anArg);
942 aFlag.LowerCase(); //!< for case insensitive comparison
943 if (aFlag == "position")
945 if ((anArgIt + 3) >= theArgsNb)
947 std::cerr << "Wrong syntax at argument '" << anArg << "'!\n";
950 aPosition[0] = Draw::Atof (theArgVec[++anArgIt]);
951 aPosition[1] = Draw::Atof (theArgVec[++anArgIt]);
952 aPosition[2] = Draw::Atof (theArgVec[++anArgIt]);
956 std::cout << "Syntax error! Unknown flag '" << anArg << "'\n";
962 @section occt_coding_rules_11 Examples
964 ### Sample documented class
970 public: //! @name public methods
972 //! Method computes the square value.
973 //! @param theValue the input value
974 //! @return squared value
975 Standard_Export Standard_Real Square (const Standard_Real theValue);
977 private: //! \@name private methods
982 private: //! \@name private fields
984 Standard_Integer myCounter; //!< usage counter
992 #include <Package_Class.hxx>
993 // ==========================================================
995 // purpose : Method computes the square value
996 // ==========================================================
997 Standard_Real Package_Class::Square (const Standard_Real theValue)
1000 return theValue * theValue;
1003 // ==========================================================
1004 // function : increment
1006 // ==========================================================
1007 void Package_Class::increment()
1013 ### TCL script for Draw Harness
1016 # show fragments (solids) in shading with different colors
1017 proc DisplayColored {theShape} {
1018 set aSolids [uplevel #0 explode $theShape so]
1020 set THE_COLORS {red green blue1 magenta1 yellow cyan1 brown}
1021 foreach aSolIter $aSolids {
1022 uplevel #0 vdisplay $aSolIter
1023 uplevel #0 vsetcolor $aSolIter [lindex $THE_COLORS [expr [incr aColorIter] % [llength $THE_COLORS]]]
1024 uplevel #0 vsetdispmode $aSolIter 1
1025 uplevel #0 vsetmaterial $aSolIter plastic
1026 uplevel #0 vsettransparency $aSolIter 0.5
1031 pload MODELING VISUALIZATION
1038 # show fragments (solids) in shading with different colors
1045 vdump $imagedir/${casename}.png 512 512
1050 vec3 Ambient; //!< Ambient contribution of light sources
1051 vec3 Diffuse; //!< Diffuse contribution of light sources
1052 vec3 Specular; //!< Specular contribution of light sources
1054 //! Computes illumination from light sources
1055 vec4 ComputeLighting (in vec3 theNormal,
1059 // clear the light intensity accumulators
1060 Ambient = occLightAmbient.rgb;
1061 Diffuse = vec3 (0.0);
1062 Specular = vec3 (0.0);
1063 vec3 aPoint = thePoint.xyz / thePoint.w;
1064 for (int anIndex = 0; anIndex < occLightSourcesCount; ++anIndex)
1066 int aType = occLight_Type (anIndex);
1067 if (aType == OccLightType_Direct)
1069 directionalLight (anIndex, theNormal, theView);
1071 else if (aType == OccLightType_Point)
1073 pointLight (anIndex, theNormal, theView, aPoint);
1077 return vec4 (Ambient, 1.0) * occFrontMaterial_Ambient()
1078 + vec4 (Diffuse, 1.0) * occFrontMaterial_Diffuse()
1079 + vec4 (Specular, 1.0) * occFrontMaterial_Specular();
1082 //! Entry point to the Fragment Shader
1085 gl_FragColor = computeLighting (normalize (Normal),