Skip to content

Commit

Permalink
animation: play only valid keyframe animations
Browse files Browse the repository at this point in the history
- show warning messages in message bar
  • Loading branch information
minorua committed Feb 25, 2022
1 parent 74b88e2 commit c716eb8
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 32 deletions.
8 changes: 8 additions & 0 deletions exportsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ def getLayer(self, layerId):
if layer.layerId == layerId:
return layer

def getLayerByJSLayerId(self, jsLayerId):
if jsLayerId is None:
return None

for layer in self.layers():
if layer.jsLayerId == jsLayerId:
return layer

def addLayer(self, layer):
"""append an additional layer to layer list"""
layer = layer.clone()
Expand Down
74 changes: 56 additions & 18 deletions keyframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,40 @@ def playButtonClicked(self, _):
def playAnimation(self, items=None, loop=False):
self.wnd.settings.setAnimationData(self.tree.data())

self._warnings = []

dataList = []
for item in (items or self.tree.checkedGroups()):
t = item.type()
if t in (ATConst.ITEM_GRP_MATERIAL, ATConst.ITEM_GRP_GROWING_LINE):
layerId = item.parent().data(0, ATConst.DATA_LAYER_ID)
layer = self.wnd.settings.getLayer(layerId)
if layer:
if t == ATConst.ITEM_GRP_MATERIAL:
layer = layer.clone()
layer.opt.onlyMaterial = True
layer.opt.allMaterials = True

self.wnd.iface.requestRunScript("preview.renderEnabled = false;")
self.wnd.iface.updateLayerRequest.emit(layer)
self.wnd.iface.requestRunScript("preview.renderEnabled = true;")

data = self.tree.transitionData(item)
if data:
dataList.append(data)
if items is None:
for group in self.wnd.settings.enabledValidKeyframeGroups(warning_log=self._log):
layerId = group.get("layerId")
if layerId is None:
dataList.append(group)
else:
layer = self.wnd.settings.getLayerByJSLayerId(layerId)
if layer:
self._updateLayer(layer, group.get("type"))
dataList.append(group)
else:
for item in items:
t = item.type()
if t in (ATConst.ITEM_GRP_MATERIAL, ATConst.ITEM_GRP_GROWING_LINE):
mapLayerId = item.parent().data(0, ATConst.DATA_LAYER_ID)
layer = self.wnd.settings.getLayer(mapLayerId)
if layer:
self._updateLayer(layer, t)

data = self.tree.transitionData(item)
if data:
dataList.append(data)

msg = ""
duration = 5000
if self._warnings:
msg = "Animation warning{}:<br><ul>".format("s" if len(self._warnings) > 1 else "")
for w in self._warnings:
msg += "<li>" + w + "</li>"
msg += "</ul>"
duration = 0

if len(dataList):
if DEBUG_MODE:
Expand All @@ -91,6 +106,29 @@ def playAnimation(self, items=None, loop=False):
self.ui.toolButtonPlay.setIcon(self.iconStop)
self.ui.checkBoxLoop.setEnabled(False)
self.isAnimating = True
else:
if not msg:
msg = "Animation: "
msg += "There are no keyframe groups to play."

self.ui.toolButtonPlay.setChecked(False)

if msg:
self.wnd.showMessageBar(msg, duration, warning=True)

def _updateLayer(self, layer, groupType):
if groupType == ATConst.ITEM_GRP_MATERIAL:
layer = layer.clone()
layer.opt.onlyMaterial = True
layer.opt.allMaterials = True

self.wnd.iface.requestRunScript("preview.renderEnabled = false;")
self.wnd.iface.updateLayerRequest.emit(layer)
self.wnd.iface.requestRunScript("preview.renderEnabled = true;")

def _log(self, msg):
self._warnings.append(msg)
logMessage("Animation: " + msg)

def stopAnimation(self):
self.webPage.runScript("stopAnimation()")
Expand Down
5 changes: 4 additions & 1 deletion q3dwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .q3dconst import LayerType, Script
from .q3dcontroller import Q3DController
from .q3dinterface import Q3DInterface
from .tools import createUid, hex_color, logMessage, pluginDir
from .tools import createUid, hex_color, js_bool, logMessage, pluginDir
from .ui.propertiesdialog import Ui_PropertiesDialog
from .ui.q3dwindow import Ui_Q3DWindow

Expand Down Expand Up @@ -266,6 +266,9 @@ def changeEvent(self, event):
def runScript(self, string, data=None, message="", sourceID="Q3DWindow.py"):
return self.ui.webView.runScript(string, data, message, sourceID=sourceID)

def showMessageBar(self, msg, duration=0, warning=False):
return self.runScript("showMessageBar(pyData(), {}, {})".format(duration, js_bool(warning)), msg)

# layer tree view
def showLayerPropertiesDialog(self, layer):
dialog = PropertiesDialog(self.settings, self.qgisIface, self)
Expand Down
41 changes: 31 additions & 10 deletions viewer/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,40 @@
-webkit-transform: translate3d(-50%, -50%, 0);
}

#messagebar {
#msgbar {
display: none;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 25px;
padding: 8px;
vertical-align: middle;
background-color: #f0f8ff;
border: 1px solid #8e998a;
}

#messagebar.warning {
#msgbar.warning {
background-color: #ffc800;
font-size: small;
}

#closemsgbar {
float: right;
color: #8e998a;
margin: 4px 10px;
line-height: 32px;
font-size: 32px;
width: 32px;
height: 32px;
text-align: center;
cursor: pointer;
}

#closemsgbar:hover {
background-color: #ffdd33;
}

#msgcontent {
padding: 8px;
}

#msgcontent ul {
margin: 0 5px;
}
</style>

Expand All @@ -78,7 +96,7 @@
</div>

<!-- popup -->
<div id="popup" style="display:none;">
<div id="popup">
<div id="closebtn">&times;</div>
<div id="popupbar"></div>
<div id="popupbody">
Expand Down Expand Up @@ -151,7 +169,10 @@ <h1>About</h1>
</div>

<div id="cover"></div>
<div id="messagebar" onclick="closeMessageBar();"></div>
<div id="msgbar">
<div id="closemsgbar">&times;</div>
<div id="msgcontent"></div>
</div>
<div id="debug"></div>

</body>
Expand Down
11 changes: 8 additions & 3 deletions viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ function init(off_screen, debug_mode) {
app.osRender(); app.osRender(); // render scene twice for output stability
});
}
else {
document.getElementById("closemsgbar").onclick = closeMessageBar;
}

if (Q3D.Config.northArrow.visible) {
app.buildNorthArrow(document.getElementById("northarrow"), 0);
Expand Down Expand Up @@ -255,8 +258,10 @@ function showMessageBar(message, duration, warning) {
if (duration) {
barTimerId = setTimeout(closeMessageBar, duration);
}
var e = document.getElementById("messagebar");
e.innerHTML = message;

document.getElementById("msgcontent").innerHTML = message;

var e = document.getElementById("msgbar");
e.style.display = "block";
if (warning) {
e.classList.add("warning");
Expand All @@ -267,7 +272,7 @@ function showMessageBar(message, duration, warning) {
}

function closeMessageBar() {
document.getElementById("messagebar").style.display = "none";
document.getElementById("msgbar").style.display = "none";
barTimerId = null;
}

Expand Down

0 comments on commit c716eb8

Please sign in to comment.