Skip to content

Commit 871f712

Browse files
committed
[webgeom] correctly handle configuration change
If configuration parameters are changed, drawing data need to be rebuild Provide internal method to clear such draw data without mutex lock. Do not reset/create draw data without established connection
1 parent e531441 commit 871f712

File tree

3 files changed

+123
-35
lines changed

3 files changed

+123
-35
lines changed

geom/webviewer/inc/ROOT/RGeomData.hxx

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ class RGeomDescription {
296296

297297
int IsPhysNodeVisible(const std::vector<int> &stack);
298298

299+
/** clear drawing data without locking mutex */
300+
void _ClearDrawData()
301+
{
302+
fDrawJson.clear();
303+
fSearchJson.clear();
304+
}
305+
299306
public:
300307
RGeomDescription() = default;
301308

@@ -311,51 +318,131 @@ public:
311318
TVirtualMutex *GetMutex() const { return fMutex; }
312319

313320
/** Set maximal number of nodes which should be selected for drawing */
314-
void SetMaxVisNodes(int cnt) { TLockGuard lock(fMutex); fCfg.maxnumnodes = cnt; }
321+
void SetMaxVisNodes(int cnt)
322+
{
323+
TLockGuard lock(fMutex);
324+
fCfg.maxnumnodes = cnt;
325+
_ClearDrawData();
326+
}
315327
/** Returns maximal visible number of nodes, ignored when non-positive */
316-
int GetMaxVisNodes() const { TLockGuard lock(fMutex); return fCfg.maxnumnodes; }
328+
int GetMaxVisNodes() const
329+
{
330+
TLockGuard lock(fMutex);
331+
return fCfg.maxnumnodes;
332+
}
317333

318334
/** Set maximal number of faces which should be selected for drawing */
319-
void SetMaxVisFaces(int cnt) { TLockGuard lock(fMutex); fCfg.maxnumfaces = cnt; }
335+
void SetMaxVisFaces(int cnt)
336+
{
337+
TLockGuard lock(fMutex);
338+
fCfg.maxnumfaces = cnt;
339+
_ClearDrawData();
340+
}
320341
/** Returns maximal visible number of faces, ignored when non-positive */
321-
int GetMaxVisFaces() const { TLockGuard lock(fMutex); return fCfg.maxnumfaces; }
342+
int GetMaxVisFaces() const
343+
{
344+
TLockGuard lock(fMutex);
345+
return fCfg.maxnumfaces;
346+
}
322347

323348
/** Set maximal visible level */
324-
void SetVisLevel(int lvl = 3) { TLockGuard lock(fMutex); fCfg.vislevel = lvl; }
349+
void SetVisLevel(int lvl = 3)
350+
{
351+
TLockGuard lock(fMutex);
352+
fCfg.vislevel = lvl;
353+
_ClearDrawData();
354+
}
325355
/** Returns maximal visible level */
326-
int GetVisLevel() const { TLockGuard lock(fMutex); return fCfg.vislevel; }
356+
int GetVisLevel() const
357+
{
358+
TLockGuard lock(fMutex);
359+
return fCfg.vislevel;
360+
}
327361

328362
/** Set draw options as string for JSROOT TGeoPainter */
329-
void SetTopVisible(bool on = true) { TLockGuard lock(fMutex); fCfg.showtop = on; }
363+
void SetTopVisible(bool on = true)
364+
{
365+
TLockGuard lock(fMutex);
366+
fCfg.showtop = on;
367+
_ClearDrawData();
368+
}
330369
/** Returns draw options, used for JSROOT TGeoPainter */
331-
bool GetTopVisible() const { TLockGuard lock(fMutex); return fCfg.showtop; }
370+
bool GetTopVisible() const
371+
{
372+
TLockGuard lock(fMutex);
373+
return fCfg.showtop;
374+
}
332375

333376
/** Instruct to build binary 3D model already on the server (true) or send TGeoShape as is to client, which can build model itself */
334-
void SetBuildShapes(int lvl = 1) { TLockGuard lock(fMutex); fCfg.build_shapes = lvl; }
377+
void SetBuildShapes(int lvl = 1)
378+
{
379+
TLockGuard lock(fMutex);
380+
fCfg.build_shapes = lvl;
381+
_ClearDrawData();
382+
}
335383
/** Returns true if binary 3D model build already by C++ server (default) */
336-
int IsBuildShapes() const { TLockGuard lock(fMutex); return fCfg.build_shapes; }
384+
int IsBuildShapes() const
385+
{
386+
TLockGuard lock(fMutex);
387+
return fCfg.build_shapes;
388+
}
337389

338390
/** Set number of segments for cylindrical shapes, if 0 - default value will be used */
339-
void SetNSegments(int n = 0) { TLockGuard lock(fMutex); fCfg.nsegm = n; }
391+
void SetNSegments(int n = 0)
392+
{
393+
TLockGuard lock(fMutex);
394+
fCfg.nsegm = n;
395+
_ClearDrawData();
396+
}
340397
/** Return of segments for cylindrical shapes, if 0 - default value will be used */
341-
int GetNSegments() const { TLockGuard lock(fMutex); return fCfg.nsegm; }
398+
int GetNSegments() const
399+
{
400+
TLockGuard lock(fMutex);
401+
return fCfg.nsegm;
402+
}
342403

343404
/** Set draw options as string for JSROOT TGeoPainter */
344-
void SetDrawOptions(const std::string &opt = "") { TLockGuard lock(fMutex); fCfg.drawopt = opt; }
405+
void SetDrawOptions(const std::string &opt = "")
406+
{
407+
TLockGuard lock(fMutex);
408+
fCfg.drawopt = opt;
409+
_ClearDrawData();
410+
}
345411
/** Returns draw options, used for JSROOT TGeoPainter */
346-
std::string GetDrawOptions() const { TLockGuard lock(fMutex); return fCfg.drawopt; }
412+
std::string GetDrawOptions() const
413+
{
414+
TLockGuard lock(fMutex);
415+
return fCfg.drawopt;
416+
}
347417

348418
/** Set JSON compression level for data transfer */
349-
void SetJsonComp(int comp = 0) { TLockGuard lock(fMutex); fJsonComp = comp; }
419+
void SetJsonComp(int comp = 0)
420+
{
421+
TLockGuard lock(fMutex);
422+
fJsonComp = comp;
423+
_ClearDrawData();
424+
}
350425
/** Returns JSON compression level for data transfer */
351-
int GetJsonComp() const { TLockGuard lock(fMutex); return fJsonComp; }
426+
int GetJsonComp() const
427+
{
428+
TLockGuard lock(fMutex);
429+
return fJsonComp;
430+
}
352431

353432
/** Set preference of offline operations.
354433
* Server provides more info to client from the begin on to avoid communication */
355-
void SetPreferredOffline(bool on) { TLockGuard lock(fMutex); fPreferredOffline = on; }
434+
void SetPreferredOffline(bool on)
435+
{
436+
TLockGuard lock(fMutex);
437+
fPreferredOffline = on;
438+
}
356439
/** Is offline operations preferred.
357440
* After get full description, client can do most operations without extra requests */
358-
bool IsPreferredOffline() const { TLockGuard lock(fMutex); return fPreferredOffline; }
441+
bool IsPreferredOffline() const
442+
{
443+
TLockGuard lock(fMutex);
444+
return fPreferredOffline;
445+
}
359446

360447
/** Get top node path */
361448
const std::vector<int>& GetSelectedStack() const { return fSelectedStack; }

geom/webviewer/src/RGeomData.cxx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ void RGeomDescription::ClearDescription()
482482
fDesc.clear();
483483
fNodes.clear();
484484
fSortMap.clear();
485-
ClearDrawData();
485+
_ClearDrawData();
486486
fDrawIdCut = 0;
487487
fDrawVolume = nullptr;
488488
fSelectedStack.clear();
@@ -1365,26 +1365,27 @@ void RGeomDescription::ProduceDrawData()
13651365
}
13661366

13671367
/////////////////////////////////////////////////////////////////////
1368-
/// Clear raw data. Will be rebuild when next connection will be established
1368+
/// Clear drawing data.
1369+
/// Will be rebuild when next connection established or new message need to be send
13691370

13701371
void RGeomDescription::ClearDrawData()
13711372
{
13721373
TLockGuard lock(fMutex);
13731374

1374-
fDrawJson.clear();
1375-
fSearchJson.clear();
1375+
_ClearDrawData();
13761376
}
13771377

13781378
/////////////////////////////////////////////////////////////////////
13791379
/// Clear cached data, need to be clear when connection broken
13801380

13811381
void RGeomDescription::ClearCache()
13821382
{
1383-
ClearDrawData();
1384-
13851383
TLockGuard lock(fMutex);
1384+
13861385
fShapes.clear();
13871386
fSearch.clear();
1387+
1388+
_ClearDrawData();
13881389
}
13891390

13901391
/////////////////////////////////////////////////////////////////////
@@ -1887,7 +1888,7 @@ bool RGeomDescription::ChangeNodeVisibility(const std::vector<std::string> &path
18871888
break;
18881889
}
18891890

1890-
ClearDrawData(); // after change raw data is no longer valid
1891+
_ClearDrawData(); // after change raw data is no longer valid
18911892

18921893
return true;
18931894
}
@@ -1958,7 +1959,7 @@ bool RGeomDescription::SelectTop(const std::vector<std::string> &path)
19581959

19591960
fSelectedStack = stack;
19601961

1961-
ClearDrawData();
1962+
_ClearDrawData();
19621963

19631964
return true;
19641965
}
@@ -1987,7 +1988,7 @@ bool RGeomDescription::SetPhysNodeVisibility(const std::vector<std::string> &pat
19871988
bool changed = iter->visible != on;
19881989
if (changed) {
19891990
iter->visible = on;
1990-
ClearDrawData();
1991+
_ClearDrawData();
19911992

19921993
// no need for custom settings if match with description
19931994
if ((fDesc[nodeid].vis > 0) == on)
@@ -1999,13 +2000,13 @@ bool RGeomDescription::SetPhysNodeVisibility(const std::vector<std::string> &pat
19992000

20002001
if (res > 0) {
20012002
fVisibility.emplace(iter, stack, on);
2002-
ClearDrawData();
2003+
_ClearDrawData();
20032004
return true;
20042005
}
20052006
}
20062007

20072008
fVisibility.emplace_back(stack, on);
2008-
ClearDrawData();
2009+
_ClearDrawData();
20092010
return true;
20102011
}
20112012

@@ -2076,7 +2077,7 @@ bool RGeomDescription::ClearPhysNodeVisibility(const std::vector<std::string> &p
20762077
for (auto iter = fVisibility.begin(); iter != fVisibility.end(); iter++)
20772078
if (compare_stacks(iter->stack, stack) == 0) {
20782079
fVisibility.erase(iter);
2079-
ClearDrawData();
2080+
_ClearDrawData();
20802081
return true;
20812082
}
20822083

@@ -2094,7 +2095,7 @@ bool RGeomDescription::ClearAllPhysVisibility()
20942095
return false;
20952096

20962097
fVisibility.clear();
2097-
ClearDrawData();
2098+
_ClearDrawData();
20982099
return true;
20992100
}
21002101

@@ -2118,7 +2119,7 @@ bool RGeomDescription::ChangeConfiguration(const std::string &json)
21182119

21192120
fCfg = *cfg; // use assign
21202121

2121-
ClearDrawData();
2122+
_ClearDrawData();
21222123

21232124
return true;
21242125
}

geom/webviewer/src/RGeomViewer.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ void RGeomViewer::Update()
163163
if (fWebHierarchy)
164164
fWebHierarchy->Update();
165165

166-
SendGeometry(0);
166+
if (fWebWindow && (fWebWindow->NumConnections() > 0))
167+
SendGeometry();
167168
}
168169

169170
//////////////////////////////////////////////////////////////////////////////////////////////
@@ -233,8 +234,7 @@ void RGeomViewer::SetDrawOptions(const std::string &opt)
233234
/// In this case method executed asynchronously - it returns immediately and image will stored shortly afterwards when
234235
/// received from the client Height and width parameters are ignored in that case and derived from actual drawing size
235236
/// in the browser. Another possibility is to invoke headless browser, providing positive width and height parameter
236-
/// explicitely
237-
///
237+
/// explicitly
238238

239239
void RGeomViewer::SaveImage(const std::string &fname, int width, int height)
240240
{

0 commit comments

Comments
 (0)