1 // Created on: 2016-11-14
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2016 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 <Graphic3d_HatchStyle.hxx>
17 #include <NCollection_AlignedAllocator.hxx>
18 #include <Standard_Atomic.hxx>
19 #include <Standard_ProgramError.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT (Graphic3d_HatchStyle, Standard_Transient)
23 static const unsigned int myPredefinedPatterns[Aspect_HS_NB][32] =
60 // Aspect_HS_GRID_DIAGONAL
95 // Aspect_HS_GRID_DIAGONAL_WIDE
165 // Aspect_HS_GRID_WIDE
200 // Aspect_HS_DIAGONAL_45
235 // Aspect_HS_DIAGONAL_135
270 // Aspect_HS_HORIZONTAL
305 // Aspect_HS_VERTICAL
340 // Aspect_HS_DIAGONAL_45_WIDE
375 // Aspect_HS_DIAGONAL_135_WIDE
410 // Aspect_HS_HORIZONTAL_WIDE
445 // Aspect_HS_VERTICAL_WIDE
484 static volatile Standard_Integer THE_HATCH_STYLE_COUNTER = Aspect_HS_NB - 1;
487 //=======================================================================
488 //function : Graphic3d_HatchStyle
490 //=======================================================================
491 Graphic3d_HatchStyle::Graphic3d_HatchStyle (const Handle(Image_PixMap)& thePattern)
493 Standard_ProgramError_Raise_if (thePattern.IsNull(), "Null pointer to a hatch pattern image");
494 Standard_ProgramError_Raise_if (
495 thePattern->SizeX() != 32 || thePattern->SizeY() != 32 || thePattern->Format() != Image_Format_Gray,
496 "Hatch pattern must be a 32*32 bitmap (Image_Format_Gray format)");
498 const Standard_Size aByteSize = thePattern->SizeBytes();
499 Handle(NCollection_AlignedAllocator) anAllocator = new NCollection_AlignedAllocator (16);
500 myPattern = new NCollection_Buffer (anAllocator);
501 myPattern->Allocate (aByteSize);
502 std::memcpy (myPattern->ChangeData(), thePattern->Data(), aByteSize);
504 myHatchType = Standard_Atomic_Increment (&THE_HATCH_STYLE_COUNTER);
507 //=======================================================================
510 //=======================================================================
511 const Standard_Byte* Graphic3d_HatchStyle::Pattern() const
513 return !myPattern.IsNull()
515 : (myHatchType < Aspect_HS_NB
516 ? (const Standard_Byte*)myPredefinedPatterns[myHatchType]
520 //=======================================================================
521 //function : DumpJson
523 //=======================================================================
524 void Graphic3d_HatchStyle::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
526 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
528 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myPattern.get())
529 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHatchType)