PLaSK library
Loading...
Searching...
No Matches
utils.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3
* Copyright (c) 2022 Lodz University of Technology
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, version 3.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*/
14
#include "
utils.hpp
"
15
16
namespace
plask
{
17
18
template
<
int
dims>
19
void
BoundingBoxCache<dims>::connect() {
20
if
(this->
object
)
21
connection_with_object = this->
object
->changed.connect(boost::bind(&
BoundingBoxCache<dims>::onObjectChanged
,
this
,
_1
), boost::signals2::at_front);
22
}
23
24
template
<
int
dims>
25
const
typename
BoundingBoxCache<dims>::BoundingBoxT
&
BoundingBoxCache<dims>::operator()
() {
26
if
(!isFresh) {
27
//if (!object) return BoundingBoxT::invalidInstance();
28
if
(!
object
)
throw
Exception
(
"boundingBoxCache is not initialized or object was deleted, so can't get bounding box"
);
29
boundingBox =
object
->getBoundingBox();
30
isFresh =
true
;
31
}
32
return
boundingBox;
33
}
34
35
template
<
int
dims>
36
void
BoundingBoxCache<dims>::onObjectChanged
(
const
GeometryObject::Event
&
evt
) {
37
//if (evt.isResize())
38
// boundingBox = static_cast<GeometryObjectD<dims>&>(evt.source())->getBoundingBox();
39
if
(
evt
.isResize()) isFresh =
false
;
40
if
(
evt
.isDelete()) {
41
object
=
nullptr
;
42
isFresh =
false
;
43
}
44
}
45
46
template
<
int
dims>
47
void
BoundingBoxCache<dims>::setObject
(
GeometryObjectD<dims>
*
object
) {
48
if
(this->
object
==
object
)
return
;
49
connection_with_object.disconnect();
50
this->
object
= object;
51
isFresh =
false
;
52
connect();
53
}
54
55
56
template
struct
PLASK_API
BoundingBoxCache<2>
;
57
template
struct
PLASK_API
BoundingBoxCache<3>
;
58
59
}
// namespace plask
plask
geometry
utils.cpp
Generated by
1.9.8