Skip to content

Commit

Permalink
Fixed povreay output formats
Browse files Browse the repository at this point in the history
POV-Ray plugin was only output .png file when using the menu option Render. It was added the other file types supported by POV-Ray - the user can choose between them by using the "File type" dropbox in the Render dialog.

NOTE:
Fixed more PovRay output formats
Thanks ekolis.
  • Loading branch information
Micheus authored and dgud committed Nov 16, 2013
1 parent 31d7b2a commit 876979e
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions plugins_src/import_export/wpc_pov.erl
Expand Up @@ -70,7 +70,7 @@ init() ->
set_var(rendering, false),
true.

%retrieve plugin preferences from prefernce file and store as global variables
%retrieve plugin preferences from preference file and store as global variables
init_pref() ->
case is_windows() of
true-> LocalRenderer = ?DEF_RENDERER;
Expand Down Expand Up @@ -102,6 +102,7 @@ init_pref() ->
true-> LocalArgs = ?DEF_RENDERARGS;
false-> LocalArgs = ?DEF_LINUX_RENDERARGS
end,
set_var(render_format, get_pref(render_format, ?DEF_RENDER_FORMAT)),
set_var(renderargs, get_pref(renderargs, LocalArgs)),
set_var(limit_vertices, get_pref(limit_vertices, true)),
set_var(use_model_dim, get_pref(use_model_dim, false)),
Expand Down Expand Up @@ -133,14 +134,17 @@ povray_menu(Menu) ->
Menu ++ [{?__(1,"POV-Ray (.pov)"),?TAG,[option]}].

%dialog and file type properties
props(render, Attr) ->
RenderFormat = proplists:get_value(render_format, Attr, ?DEF_RENDER_FORMAT),
{value, {RenderFormat, Ext, Desc}} = lists:keysearch(RenderFormat, 1, wings_job:render_formats()),
% POV-Ray output file formats: http://www.povray.org/documentation/view/3.6.0/219/
props(render, _Attr) ->
RenderFormat = get_var(render_format),
ExtsInfo=wings_job:render_formats(),
{value, {_, Ext, Desc}} = lists:keysearch(RenderFormat, 1, ExtsInfo),
Title = case os:type() of
{win32,_} -> "Render";
_Other -> ?__(1,"Render")
end,
[{title,Title}, {ext,Ext}, {ext_desc,Desc}];
Exts=get_ext_info(ExtsInfo),
[{title,Title}, {ext,Ext}, {ext_desc,Desc}, {extensions,Exts}];
props(export, _Attr) ->
{Title,File} = case os:type() of
{win32,_} -> {"Export","POV-Ray File"};
Expand Down Expand Up @@ -224,6 +228,7 @@ pref_dialog(St) ->
{?__(8,"Limit number of vertices, indices per line"), LimitVertices, [{key, limit_vertices}]}
]}],
wpa:dialog(?__(9,"POV-Ray Options"), Dialog, fun (Attr) -> pref_result(Attr,St) end).

pref_result(Attr, St) ->
set_user_prefs(Attr),
init_pref(),
Expand Down Expand Up @@ -270,7 +275,7 @@ export(Filename, Contents, Attr) ->
wpa:popup_console(),
ExportTS = erlang:now(),
Render = proplists:get_value(?TAG_RENDER, Attr, false),
RenderFormat = proplists:get_value(render_format, Attr, ?DEF_RENDER_FORMAT),
RenderFormat = get_var(render_format),
ExportDir = filename:dirname(Filename),

ContentsXForm = export_transform(Contents),
Expand Down Expand Up @@ -330,9 +335,13 @@ export(Filename, Contents, Attr) ->
wings_job:export_done(ExportTS),
io:nl();
{Renderer, true} ->
{RenderFormatId, RenderFormatStr}=get_output_param(Filename),
set_var(render_format, RenderFormatId),
set_user_prefs([{render_format, RenderFormatId}]), % it ensures global preference is updated
ArgStr = wings_job:quote(filename:basename(ExportFile))++" +W"++wings_job:quote(integer_to_list(Width))++
" +H"++wings_job:quote(integer_to_list(Height))++
" +FN +o"++wings_job:quote(filename:basename(Filename))++
" "++RenderFormatStr ++
" +o"++wings_job:quote(filename:basename(Filename))++
case proplists:get_value(antialias, Attr, false) of
false->[];
true->" +A"++ wings_util:nice_float(proplists:get_value(aa_threshold, Attr, 0.3))++
Expand Down Expand Up @@ -1900,6 +1909,44 @@ clean_name([L | Name])->
end
end.

%%%
%%% functions to manage the output file type
%%%
%% returns a list of {atom, param string} for the output file type supported by POV-Ray
pov_output_exts() ->
wings_job:render_formats(),
OSDep = case os:type() of
{win32,_} -> [{bmp,"+FS"}];
_ -> []
end,
OSDep++[{png,"+FN"},{tga,"+FT"}].

%% returns the file extension and description of the file type
get_ext_info([]) -> {"",""};
get_ext_info(ExtInfo) ->
Exts=pov_output_exts(),
lists:foldl(fun({Key,Ext,Dsc}, Acc) ->
case lists:keysearch(Key,1,Exts) of
{value,_} -> Acc++[{Ext,Dsc}];
_ -> Acc
end
end, [], ExtInfo).

%% ensure to return a valid pair {atom, param string} for output file supported by POV-Ray
get_output_param(Filename) ->
ExtsInfo=wings_job:render_formats(),
PovExts=pov_output_exts(),
{value, {_,DefParam}}=lists:keysearch(?DEF_RENDER_FORMAT,1,PovExts),
Ext=filename:extension(Filename),
case lists:keysearch(Ext, 2, ExtsInfo) of
{value, {RenderFormat, _, _}} ->
case lists:keysearch(RenderFormat,1,PovExts) of
{value, {_,Param}} -> {RenderFormat,Param};
_ -> {?DEF_RENDER_FORMAT,DefParam}
end;
_ -> {?DEF_RENDER_FORMAT,DefParam}
end.

%pulls out all the values stored as {{KeyTag, SubKey}, Value}
%returns {ListOfFound, ListRemaining}
%ListOfFound is a list of {SubKey, Value}
Expand Down

0 comments on commit 876979e

Please sign in to comment.