summaryrefslogtreecommitdiff
path: root/src/DNaming/DNaming_BoxDriver.cxx
blob: 506a7559f7bb2a30d792d1bcff540710b9740bd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// File:	DNaming_BoxDriver.cxx
// Created:	Wed Apr 29 19:00:56 2009
// Author:	Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright:	Open  CasCade SA 2009 

#include <DNaming_BoxDriver.ixx>
#include <TFunction_Function.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_Integer.hxx>
#include <TFunction_Logbook.hxx>
#include <TNaming.hxx>
#include <TNaming_NamedShape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Solid.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Real.hxx>
#include <TDF_Label.hxx>
#include <ModelDefinitions.hxx>
#include <DNaming.hxx>
#include <TNaming_Builder.hxx>
//=======================================================================
//function : DNaming_BoxDriver
//purpose  : Constructor
//=======================================================================
DNaming_BoxDriver::DNaming_BoxDriver()
{}

//=======================================================================
//function : Validate
//purpose  : Validates labels of a function in <log>.
//=======================================================================
void DNaming_BoxDriver::Validate(TFunction_Logbook& theLog) const
{}

//=======================================================================
//function : MustExecute
//purpose  : Analyse in <log> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_BoxDriver::MustExecute(const TFunction_Logbook& theLog) const
{
  return Standard_True;
}

//=======================================================================
//function : Execute
//purpose  : Execute the function and push in <log> the impacted labels
//=======================================================================
Standard_Integer DNaming_BoxDriver::Execute(TFunction_Logbook& theLog) const
{
  Handle(TFunction_Function) aFunction;
  Label().FindAttribute(TFunction_Function::GetID(),aFunction);
  if(aFunction.IsNull()) return -1;
  
  
  
// perform calculations

  Standard_Real aDX = DNaming::GetReal(aFunction,BOX_DX)->Get();
  Standard_Real aDY = DNaming::GetReal(aFunction,BOX_DY)->Get();
  Standard_Real aDZ = DNaming::GetReal(aFunction,BOX_DZ)->Get();

  Handle(TNaming_NamedShape) aPrevBox = DNaming::GetFunctionResult(aFunction);
// Save location
  TopLoc_Location aLocation;
  if (!aPrevBox.IsNull() && !aPrevBox->IsEmpty()) {
    aLocation = aPrevBox->Get().Location();
  }
  BRepPrimAPI_MakeBox aMakeBox(aDX, aDY, aDZ);  
  aMakeBox.Build();
  if (!aMakeBox.IsDone())
    {
      aFunction->SetFailure(ALGO_FAILED);
      return -1;
    }

  TopoDS_Shape aResult = aMakeBox.Solid();
  BRepCheck_Analyzer aCheck(aResult);
  if (!aCheck.IsValid (aResult))
    {
      aFunction->SetFailure(RESULT_NOT_VALID);
      return -1;
    }

    // Naming
  LoadNamingDS(RESPOSITION(aFunction),aMakeBox);

// restore location
  if(!aLocation.IsIdentity())
    TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);

  theLog.SetValid(RESPOSITION(aFunction), Standard_True);  

  aFunction->SetFailure(DONE);
  return 0;
}

//=======================================================================
//function : LoadAndName
//purpose  : 
//=======================================================================
void DNaming_BoxDriver::LoadNamingDS (const TDF_Label& theResultLabel, 
				      BRepPrimAPI_MakeBox& MS) const 
{
  TNaming_Builder Builder (theResultLabel);
  Builder.Generated (MS.Solid());

  //Load the faces of the box :
  TopoDS_Face BottomFace = MS.BottomFace ();
  TNaming_Builder BOF (theResultLabel.FindChild(1,Standard_True)); 
  BOF.Generated (BottomFace);
 
  TopoDS_Face TopFace = MS.TopFace ();
  TNaming_Builder TF (theResultLabel.FindChild(2,Standard_True)); 
  TF.Generated (TopFace); 

  TopoDS_Face FrontFace = MS.FrontFace ();
  TNaming_Builder FF (theResultLabel.FindChild(3,Standard_True)); 
  FF.Generated (FrontFace); 

  TopoDS_Face RightFace = MS.RightFace ();
  TNaming_Builder RF (theResultLabel.FindChild(4,Standard_True)); 
  RF.Generated (RightFace); 

  TopoDS_Face BackFace = MS.BackFace ();
  TNaming_Builder BF (theResultLabel.FindChild(5,Standard_True)); 
  BF.Generated (BackFace); 

  TopoDS_Face LeftFace = MS.LeftFace ();
  TNaming_Builder LF (theResultLabel.FindChild(6,Standard_True)); 
  LF.Generated (LeftFace); 
}